关于mysql的联合查询,如何从两个不同的表中汇总数据

发布网友 发布时间:2022-04-21 07:23

我来回答

2个回答

热心网友 时间:2022-06-18 16:48

使用UNION
select DEPT_NAME, USER_NAME, PHONE, CONTENT, SEND_TIME from sms3
UNION ALL
select DEPT_NAME,SENDER_NAME,MOBIL_NO ,CONTENT,DIA_TIME from diary

在每个select 语句中可以使用where 条件指定数据
两个表的对应列类型最好一致

SELECT ...
UNION [ALL | DISTINCT] SELECT ...
[UNION [ALL | DISTINCT] SELECT ...]

UNION is used to combine the result from multiple SELECT statements into a single result set.

The column names from the first SELECT statement are used as the column names for the results returned. Selected columns listed in corresponding positions of each SELECT statement should have the same data type. (For example, the first column selected by the first statement should have the same type as the first column selected by the other statements.)

热心网友 时间:2022-06-18 16:48

select +“需要显示的字段”+from sms3 as a inner join diary as b on a. DEPT_NAME=b.DEPT_NAME where +"加上自己的查询条件"

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com