我看到了一些关于我的问题的其他帖子,但我认为我的更具体,但对于专业人士来说也很容易。
我有一个像这样的表(name = List):
date price
'2017-01-03' 12
'2017-01-04' 10
'2017-01-05' 11
'2017-02-01' 8
'2017-02-02' 6
'2017-03-02' 14
...
第二个(姓名=宪法),每个月的第一个:
Date
'2017-01-01'
'2017-02-01'
'2017-03-01'
给出了这些。也许我甚至不必使用第二个。最后,我希望在“List”中每个月都有可用的每个第一天的日期,如下所示:
date price
'2017-01-03' 12
'2017-02-01' 8
'2017-03-02' 14
...
我的尝试:
Select min(List.Date)
from List inner join Constituents
on List.Date=Constituents.Date
where datepart(year,List.Date)=datepart(year,Constituents.Date)
and datepart(month,List.Date)=datepart(month,Constituents.Date)
在这个查询中我没有得到任何价值(德语错误信息)。请帮忙。
答案 0 :(得分:0)
你可以尝试这样做:
SELECT *
FROM List
WHERE Date IN (
SELECT MIN(List.Date)
FROM List
GROUP BY MONTH(List.Date), YEAR(List.Date)
)