[英]How to use multiple Select statement in MySQL
Lets say i want to select (total Number of Customer from Customer table), as well as (Total Sum of transaction Amount from transaction Table). 假设我要选择(“客户”表中的“客户总数”)以及(“交易表”中的“交易总额”)。
I want to list out both result in single query.. 我想在单个查询中列出两个结果。
select Count(id) from Customer
select Sum(Amount) from Transactions
Please help me to to do. 请帮我做。
You can put the two queries in subqueries: 您可以将两个查询放在子查询中:
SELECT (SELECT COUNT(*) FROM Customer) AS customers,
(SELECT SUM(amount) FROM Transactions) AS amount
FROM DUAL
You don't need FROM DUAL
if you're doing this in MySQL, you may need it in other databases. 如果在MySQL中执行此操作,则不需要
FROM DUAL
,而在其他数据库中可能需要它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.