-1
我有三個SQL查詢:如何合併這三個SQL查詢?
首先查詢:
SELECT DISTINCT company.company_name AS CompanyName, pts AS CompanyPts
FROM users_pts, users_codes, company
WHERE scanned = 1
AND users_codes.company_id = company.company_id
AND users_codes.company_id = users_pts.company_id
AND users_codes.email = '[email protected]'
GROUP BY company.company_id
第二個查詢:
SELECT SUM(IF(completed = 0, 1, 0)) AS NumberOfSurveys
FROM users_survey_answers
WHERE users_survey_answers.email = '[email protected]'
GROUP BY users_survey_answers.company_id
第三個查詢:
SELECT SUM(IF(redeemed = 0, 1, 0)) AS NumberOfRewards
FROM users_rewards
WHERE users_rewards.email = '[email protected]'
GROUP BY users_rewards.company_id
電子郵件列在所有數據庫,所以不用擔心你從哪裏得到它。 (無論是users_rewards.email還是users_survey_answers.email,沒關係)
我只是需要幫助才能入門。
謝謝你們
嘿感謝快速回復做到這一點。我嘗試了他們兩個,它給我「#1305 - 功能mydb.sum不存在」 – user1025013
你使用哪種rdbms? –
我通過刪除「SUM(」然而,我得到這個錯誤「在'子句'」 – user1025013