我有这三个 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 = 'test@gmail.com'
GROUP BY company.company_id
第二个查询:
SELECT SUM(IF(completed = 0, 1, 0)) AS NumberOfSurveys
FROM users_survey_answers
WHERE users_survey_answers.email = 'test@gmail.com'
GROUP BY users_survey_answers.company_id
第三个查询:
SELECT SUM(IF(redeemed = 0, 1, 0)) AS NumberOfRewards
FROM users_rewards
WHERE users_rewards.email = 'test@gmail.com'
GROUP BY users_rewards.company_id
电子邮件列在所有数据库中,所以不用担心你从哪里得到它。(不管是users_rewards.email还是users_survey_answers.email,都无所谓)
我只需要帮助开始。
多谢你们