Subject | Summary SQL question |
---|---|
Author | diwic2 |
Post date | 2005-03-04T15:25:29Z |
I have this table, and Firebird 1.5.0:
uskid fm fm2
1 3 4
1 3 4
1 4 4
2 2 3
2 4 3
3 3 2
I want some way to know how many 2:s, 3:s and 4:s there is in column
fm and fm2, per uskid.
Something like:
select uskid, count(fm = 2), count(fm = 3), count(fm = 4),
count(fm2 = 2), count(fm2 = 3), count(fm2 = 4)
from mytable
group by uskid
The expected result would be:
1, 0, 2, 1, 0, 0, 3
2, 1, 0, 1, 0, 2, 0
3, 0, 1, 0, 1, 0, 0
Of course, that's not valid SQL syntax, but I guess you understand how
I mean. How do I do it?
// David
uskid fm fm2
1 3 4
1 3 4
1 4 4
2 2 3
2 4 3
3 3 2
I want some way to know how many 2:s, 3:s and 4:s there is in column
fm and fm2, per uskid.
Something like:
select uskid, count(fm = 2), count(fm = 3), count(fm = 4),
count(fm2 = 2), count(fm2 = 3), count(fm2 = 4)
from mytable
group by uskid
The expected result would be:
1, 0, 2, 1, 0, 0, 3
2, 1, 0, 1, 0, 2, 0
3, 0, 1, 0, 1, 0, 0
Of course, that's not valid SQL syntax, but I guess you understand how
I mean. How do I do it?
// David