I have a table with the inscriptions and next to them:
id | label | code
1 | foo | 21
2 | foo | 33
3 | foo | 33
4 | foo | 13
5 | foo | 13
6 | foo | 33
7 | bar | 13
8 | bar | 13
9 | bar | 33
10 | smt | 33
11 | smt | 13
I need a query that selects the high frequencies of the "code" for each "tag". Here is what I still have:
SELECT count(*) frequency, label, code
FROM myTable
GROUP BY label, code
This gives me:
frequency | label | code
1 | foo | 21
3 | foo | 33
2 | foo | 13
2 | bar | 13
1 | bar | 33
1 | smt | 33
1 | smt | 13
I would like to:
frequency | label | code
3 | foo | 33
2 | bar | 13
1 | smt | 33
1 | smt | 13
As you can see, for "foo" and "bar" only the high frequencies are selected. Since "smt" does not have a maximum frequency as such (all are the same), all lines are included.
I have no idea, even where to start. Can anybody help? Thank you (By the way, I'm using mssql)
source
share