嗨,我对我的sql是新的,我正在尝试乘法和添加我的子查询的结果,但是我的查询不起作用,它总是为每行提供0输出
我的栏目好像这个总栏目的输出是错误的
Val1 Income Val2 Total
1 5 5 0
1 1 8 0
1 1 7 0
5 7 6 0
我的问题是这样的
SELECT
COUNT(DISTINCT t1.id) AS 'Val1',
(SELECT SUM(CAST(COALESCE(r.t_payment_total,0) AS DECIMAL(18,2))) AS 'Income'
FROM reserv r
INNER JOIN newtbladds1 t ON t.t_parent_id = r.id
WHERE r.t_status!="Pending" && r.t_status!="Booked" AND r.c_mid = m.id AND t.t_type_id = t1.t_type_id
)AS 'Income',
num1 AS 'Val2',
'Val1'*'Income'+ 'Val2' as 'Total'
FROM tbladds1 t1
JOIN tbladds1_type tt ON tt.id = t1.t_type_id
JOIN tbladdress m ON m.id = t1.t_mid
JOIN tbladdressfr mf ON mf.id = t1.t_floor_id
JOIN tblppl mp ON mp.t_mid = m.id AND mp.t_type = 'try' AND mp.t_system_id = 'ok'
GROUP BY t1.t_tool_type_id
ORDER BY m.t_m ASC, tt.t_ttype ASC, mf.t_floor ASC;
期望的输出是这样的。我将非常感谢任何帮助或建议谢谢
Val1 Income Val2 Total
1 5 5 10
1 1 8 8
1 1 7 7
5 7 6 41
暂无答案!
目前还没有任何答案,快来回答吧!