如果表中包含所有日期,则可以将其用作源。然后一个cross join
和left join
:
select uc.user, uc.client, d.date,
coalesce(st.total, 0)
from (select distinct user, client
from sampletable
) uc cross join
(select distinct date
from sampletable
) d left join
sampletable st
on st.user = uc.user and st.client = uc.client and
st.date = d.date;
如果基表没有所有日期,您可以通过多种方式生成它们:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句