我想要一个查询,只选择那些有指定年份数据的月份,但我不太清楚如何实现这一目标。这是我到目前为止所得到的:
select MONTH(DateRaised) as 'Month'
from Complaints
where
(select COUNT(*)
from Complaints
where YEAR(DateRaised) = 2000) > 0
group by MONTH(dateraised)
order by MONTH(dateraised)
因此,如果我的数据在2000年的5月,8月和12月有投诉,那么我只希望5, 8 and 12
出现在我的查询中,这可能吗?
答案 0 :(得分:2)
select MONTH(DateRaised) as 'Month'
from Complaints
where YEAR(DateRaised) = 2000
ORDER BY MONTH(dateraised)
答案 1 :(得分:2)
select DISTINCT MONTH(DateRaised) AS 'Month'
from Complaints
where YEAR(DateRaised) = 2000
答案 2 :(得分:1)
SELECT MONTH(DateRaised) as 'Month', COUNT(*) AS count
FROM Complaints
WHERE YEAR(DateRaised) = 2000
GROUP BY MONTH(dateraised)
ORDER BY MONTH(dateraised)