Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to index alias database column

How to index alias database column

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 2 Posters 443 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by
    #1

    I want to index the Age column which is an alias column of the table below. The first two line works perfectly but trying to index the alias column using Age = self.ui.label_572.setText(query[2]) does not return any value, please any help on what I'm doing wrong.

    Table

    Screenshot (84).png

    Code

    name = self.ui.label_570.setText(query[0])
    DOB = self.ui.label_571.setText(query[1])
    Age = self.ui.label_572.setText(query[2])
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which database backend are you using ?
      What kind of query do you use ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which database backend are you using ?
        What kind of query do you use ?

        L Offline
        L Offline
        LT-K101
        wrote on last edited by
        #3

        @SGaist Hi, I'm using sqlite

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you answer all the questions ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you answer all the questions ?

            L Offline
            L Offline
            LT-K101
            wrote on last edited by
            #5

            @SGaist sorry, I'm using sqlite and below is the query I executed.

            con = sqlite3.connect("ClientsDatabase.db")
            
            cur.execute( ''' SELECT name,dob, strftime('%Y',date('now'))-strftime('%Y',date(dob))
            , CASE
              WHEN strftime('%m', date('now')) > strftime('%m', date(dob)) THEN strftime('%Y', date('now')) - strftime('%Y', date(dob))
                WHEN strftime('%m', date('now')) = strftime('%m', date(dob)) THEN 
                    CASE
                        WHEN strftime('%d', date('now')) >= strftime('%d', date(dob)) THEN strftime('%Y', date('now')) - strftime('%Y', date(dob))
                        ELSE strftime('%Y', date('now')) - strftime('%Y', date(dob)) - 1	
                    END
                WHEN strftime('%m', date('now')) < strftime('%m', date(dob)) THEN strftime('%Y', date('now')) - strftime('%Y', date(dob)) - 1
            
            END AS 'Age' FROM client_details)
            
            query = cur.fetchone()
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved