Query a table to get values ​​based on missing parameter digits?

Given the following table

I have a large table from which I can run a query to get the following table

type       no of times type occurs
101            450
102            562
103            245
111            25
112            28
113            21

      

Now, suppose I wanted to get a table that shows me that the sum of the number of times, for a type starting with 1, then starting at 10,11,12,13 ....... 19, then starting at 2, 20 , 21, 22, 23 ... 29, etc.

Something like that

1        1331               10        1257
                            11        74
                            12         ..
                            13         ..
                            ..         ..
2        ...                20         ..
                            21         ..

      

Hope I'm clear Thanks

0


source to share


2 answers


You actually have two different requests:

SELECT [type]\100 AS TypePart, Count(t.type) AS CountOftype
FROM t
GROUP BY [type]\100;

      

and



SELECT [type]\100 AS TypePart, [type] Mod 100 AS TypeEnd, 
    Count(t.type) AS CountOftype
FROM t
GROUP BY [type]\100, [type] Mod 100;

      

Where t is the name of the table.

0


source


Here in the first request I get something like this

utypPart    CountOftype
    1   29
    2   42
    3   46
    4   50
    5   26
    6   45
    7   33
    9   1

      



this gives me how many utyp starts with 1 2 and so on but whai i want this is the sum not of the times these types occur for utyp.

0


source







All Articles