嗨,我有一个 sql 查询,我遇到了一个条件,因为我是新手sql
select * from Today
LEFT JOIN
TABLEPricing Yesterday ON
Yesterday.Date = (select top 1 date from #Dates where MONTH(DATE) = MONTH(Today.Date)-1 AND YEAR(DATE) = YEAR(Today.Date))
LEFT JOIN Prev ON
Prev.Date = Yesterday.Date
在第二个条件Prev.Date = Yesterday.Date
中,将自动预先为likeYesterday.Date
赋值表达式Yesterday.Date
Yesterday.Date = (select top 1 date from #Dates where MONTH(DATE) = MONTH(Today.Date)-1 AND YEAR(DATE) = YEAR(Today.Date))
或者我需要再次指定相同的条件,如下所示。
Prev.Date = (select top 1 date from #Dates where MONTH(DATE) = MONTH(Today.Date)-1 AND YEAR(DATE) = YEAR(Today.Date))
请澄清我很困惑。