-1
在表格和羣組上加入2個表格並進行多項查詢請幫助我的學校營銷項目。我正在尋找整天,並嘗試我的代碼工作,我也嘗試了一些在這裏stackoverflow的答案,但我不能得到正確的結果。請看我上傳的表格圖片。
TABLES image here please click如何通過
SELECT d.user_ID, d.weekof,
TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(d.total_time))), '%H:%i') AS st_time, SUM(d.twcm) AS stwcm, SUM(d.slas) AS sslas, SUM(d.bas) AS sbas, SUM(d.iph) AS siph, SUM(d.ias) AS sias,
SUM(IF(d.lead_type = 'expireds', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS expireds,
SUM(IF(d.lead_type = 'fsbos', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS fsbos,
SUM(IF(d.lead_type = 'followup', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS followup,
SUM(IF(d.lead_type = 'buyers', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS buyers,
SUM(IF(d.lead_type = 'agents', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS agents,
SUM(IF(d.lead_type = 'circlemarketing', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS circlemarketing,
SUM(IF(d.lead_type = 'doorknocking', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS doorknocking,
SUM(IF(d.lead_type = 'investor', d.twcm + d.slas + d.bas + d.iph + d.ias, 0)) AS investors,
w.user_ID, w.weekof, SUM(w.slah) AS sslah, SUM(w.bah) AS sbah, SUM(w.sls) AS ssls, SUM(w.bls) AS sbls, SUM(w.nuc) AS snuc
FROM daily_table d
JOIN weekly_table w ON d.user_ID = w.user_ID
WHERE d.user_ID = 'kien'
GROUP BY weekof
新的更新的代碼,但結果總和()是不正確的總和。
SELECT w.user_ID, w.weekof, SUM(w.slah) AS sslah, SUM(w.bah) AS sbah, SUM(w.sls) AS ssls, SUM(w.bls) AS sbls, SUM(w.nuc) AS snuc,
d.user_ID, TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(d.total_time))), '%H:%i') AS st_time, SUM(d.twcm) AS stwcm, SUM(d.slas) AS sslas,
SUM(d.bas) AS sbas, SUM(d.iph) AS siph, SUM(d.ias) AS sias,
SUM(IF(d.lead_type = 'expireds', twcm + slas + bas + iph + ias, 0)) AS expireds,
SUM(IF(d.lead_type = 'fsbos', twcm + slas + bas + iph + ias, 0)) AS fsbos,
SUM(IF(d.lead_type = 'followup', twcm + slas + bas + iph + ias, 0)) AS followup,
SUM(IF(d.lead_type = 'buyers', twcm + slas + bas + iph + ias, 0)) AS buyers,
SUM(IF(d.lead_type = 'agents', twcm + slas + bas + iph + ias, 0)) AS agents,
SUM(IF(d.lead_type = 'circlemarketing', twcm + slas + bas + iph + ias, 0)) AS circlemarketing,
SUM(IF(d.lead_type = 'doorknocking', twcm + slas + bas + iph + ias, 0)) AS doorknocking,
SUM(IF(d.lead_type = 'investor', twcm + slas + bas + iph + ias, 0)) AS investors
FROM wp_weekly_goals w LEFT JOIN wp_daily_goals d ON d.weekof=w.weekof GROUP BY weekof
我有更新代碼在這裏,但結果總和(0數字是不正確的 –