SELECT users.firstname from users
INNER JOIN user_ps
ON user_ps.user_id=users.id where user_id=23 group BY user_ps.user_id
SELECT SUM(best + better + good) from user_ps as total where user_id=23
嗨,我是新用户,我需要帮助,如何在一个查询中将两者结合起来,请帮助我
答案 0 :(得分:0)
您可以使用union
组合它SELECT users.firstname from users
INNER JOIN user_ps
ON user_ps.user_id=users.id where user_id=23 group BY user_ps.user_id
UNION
SELECT SUM(best + better + good) from user_ps as total where user_id=23
答案 1 :(得分:0)
试试这个: -
SELECT users.firstname, SUM(best + better + good) AS Total
FROM users INNER JOIN user_ps
ON user_ps.user_id=users.id
WHERE user_id=23
GROUP BY users.firstname;