Results 1 to 2 of 2

Thread: Conversion and change in QTableView + SQL

  1. #1
    Join Date
    Mar 2016
    Posts
    10
    Qt products
    Qt5
    Platforms
    Windows

    Default Conversion and change in QTableView + SQL

    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 you 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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Conversion and change in QTableView + SQL

    With a table like this:
    Qt Code:
    1. create table test( month number, code varchar(10) );
    To copy to clipboard, switch view to plain text mode 
    Something like this should get you close:
    Qt Code:
    1. Select count(*), month, substr(code, 1, 2)
    2. From test
    3. Group by month, substr(code, 1, 2)
    4. Order by month, substr(code, 1, 2);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Change QTableview
    By wparja in forum Newbie
    Replies: 2
    Last Post: 12th September 2011, 17:38
  2. How can I change row heigth in QTableView?
    By Tamara in forum Qt Programming
    Replies: 8
    Last Post: 18th August 2011, 20:41
  3. Change QTableView orientation
    By r2d2u2 in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2010, 10:30
  4. Replies: 2
    Last Post: 26th November 2009, 04:45
  5. Change value inside QTableView or QSqlQuery
    By jano_alex_es in forum Newbie
    Replies: 1
    Last Post: 15th May 2009, 10:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.