0

我想要一个查询,它只选择那些具有指定年份数据的月份,但我不太确定如何实现这一点。这是我到目前为止所得到的:

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出现在我的查询中,这可能吗?

4

3 回答 3

2
select MONTH(DateRaised) as 'Month'
from Complaints
where YEAR(DateRaised) = 2000
ORDER BY MONTH(dateraised)
于 2013-01-08T09:22:58.350 回答
2
select DISTINCT MONTH(DateRaised) AS 'Month'
from Complaints
where YEAR(DateRaised) = 2000
于 2013-01-08T09:23:24.740 回答
1
SELECT MONTH(DateRaised) as 'Month', COUNT(*) AS count
FROM Complaints
WHERE YEAR(DateRaised) = 2000
GROUP BY MONTH(dateraised)
ORDER BY MONTH(dateraised)
于 2013-01-08T09:23:25.093 回答