PDA

View Full Version : Conversion and change in QTableView + SQL



ro12man3
22nd March 2016, 21:37
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.

ChrisW67
26th March 2016, 22:01
With a table like this:

create table test( month number, code varchar(10) );

Something like this should get you close:


Select count(*), month, substr(code, 1, 2)
From test
Group by month, substr(code, 1, 2)
Order by month, substr(code, 1, 2);