我使用下面的代码从表中获取每个记录总金额,但是没有得到正确的结果。 它从表中获得单个记录但我需要从我的表中获得总记录
SELECT
ur.user_id, ur.user_fullname, ur.user_status, ur.user_mobileno,
sum(pr.pre_amount) AS achivedamt
FROM users_register ur
INNER JOIN prepostings pr
ON ur.user_id=pr.user
答案 0 :(得分:0)
试试这个波纹管代码,我希望能解决你的问题。
SELECT ur.user_id,ur.user_fullname,ur.user_status,ur.user_mobileno,
sum(pr.pre_amount) AS achivedamt
FROM users_register ur INNER JOIN prepostings pr
ON ur.user_id=pr.user group by ur.user_id
答案 1 :(得分:0)
您可以在查询中添加GROUP BY:
SELECT
ur.user_id
,ur.user_fullname
,ur.user_status
,ur.user_mobileno
,sum(pr.pre_amount) AS achivedamt
FROM users_register ur
INNER JOIN prepostings pr ON ur.user_id=pr.user
GROUP BY ur.user_id