SELECT a.agent, a.talktime, a.percentclosed,COALESCE(COUNT(b.dealamount),0),COALESCE(SUM(b.dealamount),0) , b.dealdate
FROM closers a
LEFT JOIN deals b ON a.agent = b.agent
WHERE b.dealdate IS NULL OR YEARWEEK( b.dealdate ) = YEARWEEK( NOW( ) )
GROUP BY a.agent
ORDER BY COALESCE( SUM( b.dealamount ) , 0 ) DESC

有人能帮我解决这个问题吗?我知道它很混乱,但我对这个还不熟悉,
这对本周来说很好,但如果我加上+1来模拟未来一周,那么前一周有交易的所有人都不会显示出来,
谢谢,
厕所,
查询的图像

最佳答案

WeekofYear在这种情况下不好,因为它将在年底结束。你应该使用YearWeek()。

WHERE b.dealdate IS NULL OR YEARWEEK( b.dealdate ) = YEARWEEK( NOW( ) ) +1

09-25 17:21