1084:不可以同时使用大于和小于
作者:互联网
方法一:
select product_id,product_name from ( select a.product_id,product_name, case when sale_date<='2019-03-31' and sale_date>='2019-01-01' then 0 else 1 end d #case when sale_date between '2019-01-01' and '2019-03-31' then 0 else 1 end d
from Sales a left join Product b on a.product_id=b.product_id ) a group by product_id having sum(d)=0;
注意:这里不可以这么写
#case when '2019-01-01'<=sale_date<='2019-03-31' then 0 else 1 end d。这么写相当于没有写。
方法二:直接group by然后having筛选日期条件
select a.product_id,product_name from Sales a left join Product b on a.product_id=b.product_id group by a.product_id having min(sale_date)>='2019-01-01' and max(sale_date)<='2019-03-31' ;
方法三:太秀了
select a.product_id,product_name from Sales a left join Product b on a.product_id=b.product_id group by a.product_id having sum(sale_date between '2019-01-01' and '2019-03-31')=count(*);
标签:小于,product,01,sale,1084,2019,date,大于,id 来源: https://www.cnblogs.com/hugrice/p/14942210.html