简体   繁体   English

如何在MySQL中使用多个Select语句

[英]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 ,而在其他数据库中可能需要它。

You can use join statement to join both table and get data from each table. 您可以使用join语句连接两个表并从每个表中获取数据。 For join statement refer this link or you can use 对于join语句,请参考此链接,或者您可以使用

SELECT t1.*,t2.* FROM t1,t2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM