嗨,我是我的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