Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Conversion and change in QTableView + SQL
Forum Updated to NodeBB v4.3 + New Features

Conversion and change in QTableView + SQL

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.4k 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.
  • D Offline
    D Offline
    derilshows
    wrote on last edited by derilshows
    #1

    Hello! Really I need your advice.

    There are database, where in one column in the form of written codes: 10, 10-09, 10-10, 10-11, 15, 15-02, 15-03, and so on. Each value corresponds to month (in numerical format). I do a SQL query, which displays what codes in which month, with the calculation of how many times were called. The request appears in QTableView.

    In this way: HOW MANY TIMES HAS BEEN CALLED, IN WHAT MONTH, WHAT CODE.

    For example, the output will be:
    125, 04, 10-09
    4, 04, 10-10
    93, 05, 15-02
    43, 05, 15-03

    What I want:

    All codes that start with the same two numbers must be united in a single line, and only those already displayed by the first two digits. But I want to save sort by month in order to the codes of the different months are not stuck together. Naturally, the first column (the number of times was called) for concatenating should summarize the respective values of the rows that are glued together.

    As a result, should leave as follows:
    129, 04, 10
    136, 05, 15

    Can you solve this issue purely SQL? Or you need to use QT model?
    Please help, just can not imagine how to do it.

    D 1 Reply Last reply
    0
    • D derilshows

      Hello! Really I need your advice.

      There are database, where in one column in the form of written codes: 10, 10-09, 10-10, 10-11, 15, 15-02, 15-03, and so on. Each value corresponds to month (in numerical format). I do a SQL query, which displays what codes in which month, with the calculation of how many times were called. The request appears in QTableView.

      In this way: HOW MANY TIMES HAS BEEN CALLED, IN WHAT MONTH, WHAT CODE.

      For example, the output will be:
      125, 04, 10-09
      4, 04, 10-10
      93, 05, 15-02
      43, 05, 15-03

      What I want:

      All codes that start with the same two numbers must be united in a single line, and only those already displayed by the first two digits. But I want to save sort by month in order to the codes of the different months are not stuck together. Naturally, the first column (the number of times was called) for concatenating should summarize the respective values of the rows that are glued together.

      As a result, should leave as follows:
      129, 04, 10
      136, 05, 15

      Can you solve this issue purely SQL? Or you need to use QT model?
      Please help, just can not imagine how to do it.

      D Offline
      D Offline
      derilshows
      wrote on last edited by
      #2

      @derilshows Does someone know how to do that?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        derilshows
        wrote on last edited by
        #3

        I found the solution, but only by SQL query.

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

          Hi,

          Can you share that solution for other to benefit ?

          Why would it be a problem doing it only by SQLqueries ?

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

          D 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Can you share that solution for other to benefit ?

            Why would it be a problem doing it only by SQLqueries ?

            D Offline
            D Offline
            derilshows
            wrote on last edited by derilshows
            #5

            @SGaist sure. The structure is:
            HOW MANY TIMES HAS BEEN CALLED, IN WHAT MONTH, WHAT CODE.
            COUNT(*), MONTHZ, CODE
            That code is the answer:

            
            SELECT sum(cnt), monthz, code FROM (SELECT COUNT(*) AS cnt, monthz, LEFT(code, 2) AS code FROM tab GROUP BY monthz, code ) AS src;
            

            I couldn't do that, cause I did SUM(COUNT(*)), but it's incorrect.
            But we can make query from the result of other query! And it works.
            sum(cnt) makes sum of values.
            and group makes one line

            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