我还需要按Column3将该信息分组。
除了“ when column2 =“ y”外,我几乎可以做所有事情。我尝试过的代码是这样的:
select column3 ,count(column1) as asd
from maps
group by column3;
例如,如果我的桌子是
Month | Day | Column3
1 | Sun YES
1 | Mon NO
1 | Tue NO
1 | Wed YES
1 | Thu YES
1 | Fri NO
1 | Sun YES
1 | Mon YES
1 | Tue YES
2 | Wed NO
例如,我期望寻找当column = 1时,Column3 =“ YES”的时间,按天分组。因此,我希望获得类似的东西
Month | Day | asd
1 | Sun 2
1 | Mon 1
1 | Tue 1
1 | Wed 1
1 | Thu 1
1 | Fri 0
答案 0 :(得分:0)
为此,您使用where子句。
select column3 ,count(column1) as asd
from maps
where column2 = 'y'
group by column3;
因此,可能是这样的:Column3 =“ YES”,当month = 1时,按天分组:
select day ,count(*) as count
from maps
where month = 1 and column3 = 'YES'
group by day;