select userid, substr(indate,1,10) as day,count(*) as products from ybdw_productInfo_unique_d
where sta = 0 and isshelvesnow = 1
group by substr(indate,1,10),userid;
会出现这样的重复数据
userid, day, products
726651 2019/1/15 4
726651 2019/1/15 4
726651 2018/12/21 1
726651 2018/12/21 1
726651 2019/1/4 4
726651 2019/1/4 4
726651 2018/12/20 1
726651 2018/12/20 1
group by substr(indate,1,10),userid;
你是日期group by你看你日期是没有重复了吧
加上distinct就好了
把groupby后的substr(indate,1,10) 替换成 day,这样:
select userid, substr(indate,1,10) as day,count(*) as products from ybdw_productInfo_unique_d
where sta = 0 and isshelvesnow = 1
group by day,userid;
group by substr(indate,1,10).
可能有空字符,可以试一下trim函数。select userid, trim(substr(indate,1,10) ) as day,count(*) as products from ybdw_productInfo_unique_d
where sta = 0 and isshelvesnow = 1
group by trim(substr(indate,1,10)),userid;
你按照indate前十位分组肯定有重复咯、你可以把userid放前面试试