用标准SQL写是么?其实都应该差不多的
例如:
表名tableBaby
字段:BabyId …… BirthMonth
SELECT 语句:
SELECT count(BabyId)
FROM tableBaby
WHERE BirthMonth
IN ('1','2','3') //季度条件:春天
如果要统计某年某月的,表中再加个字段BirthYear
则查询语句最后加上
AND BirthYear = '1980';
例如:
表名tableBaby
字段:BabyId …… BirthMonth
SELECT 语句:
SELECT count(BabyId)
FROM tableBaby
WHERE BirthMonth
IN ('1','2','3') //季度条件:春天
如果要统计某年某月的,表中再加个字段BirthYear
则查询语句最后加上
AND BirthYear = '1980';
select * from
(select ...,product,sum(...),date from
(select ...,case when 2002-01-01 =< date and date < 2002-04-01
then 2002-03-31
when ...
end as date
from table ) as temp
group by ...,product,date ) as temp1
where temp1.date = 2002-03-31
你的回答很典型,是我不愿见到的答案,也怪我事先没说清楚,就是要有灵活性,例如你的帖子里充满了2002等,这就失去了灵活性,希望再接再厉!
BirthYear BirthMonth
那是表中的字段啊
可以是时间DATE类型,也可以是CHAR或者其它类型,那么SELECT的条件则要随之而改变了