如何将这两个查询合并到一个表中。它们是两个不同的结果,所以我需要它们是两个不同的列。我已经尝试过UNION,但是将它们放在一列中。
SELECT COUNT(*) AS Number_Customers FROM customer
Where cus_balance > 0;
Select SUM(cus_balance) AS Total_Balances
FROM customer;
答案 0 :(得分:0)
将它们重写为子查询,并使用DUAL
作为虚拟表。
SELECT
(SELECT COUNT(*) FROM customer WHERE cus_balance > 0) AS Number_Customers,
(SELECT SUM(cus_balance) FROM customer) AS Total_Balances
FROM DUAL;
如果WHERE
条款可能相同,那么你可以这样写:
SELECT COUNT(*) AS Number_Customers,
SUM(cus_balance) AS Total_Balances
FROM Cusomers
WHERE cus_balance > 0;