怎么把下面两条sql写条一条sql
1.
select * from Table_Teacher as c where c.state between 2 and 4 and c.addby='chris' and c.location in
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')
and c.ets like '%et1%' order by c.state asc, c.addtime desc
结果显示3条2.
select * from Table_Teacher as c where c.state in(1,2,10) and c.addby='chris' and c.location in
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')
and (c.ets is null or c.ets not like '%es1%') order by c.state asc, c.addtime desc
结果显示124条3.我要怎么把这两个sql合并,写成一条sql语句
1.
select * from Table_Teacher as c where c.state between 2 and 4 and c.addby='chris' and c.location in
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')
and c.ets like '%et1%' order by c.state asc, c.addtime desc
结果显示3条2.
select * from Table_Teacher as c where c.state in(1,2,10) and c.addby='chris' and c.location in
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')
and (c.ets is null or c.ets not like '%es1%') order by c.state asc, c.addtime desc
结果显示124条3.我要怎么把这两个sql合并,写成一条sql语句
解决方案 »
- mysql添加默认约束
- 请教一个SQL语句
- 通过逗号将一条记录分离成多条
- mysql 如果判断添加是否成功
- 一个数据库有大约 1w个表,会不会影响数据库查询的效率,数据几乎是不改变的!!
- ADO 操作 MYSQL和SQLserver有什么不同
- *****各位大侠,以后多多关照!!*****只能散 100 分 ???
- 一个小程序的数据项应该有那些?
- 为什么我在dos下已经进入数据库了,输入命令却毫无反应(如图),问题出在哪了?
- 求一个sql,级联查询,最好是一个sql兼容oracle和mysql
- LOAD DATA is not allowed in stored procedures
- 【MYSQL】自定义函数获取当前表名和字段名
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')
and c.ets like '%et1%' order by c.state asc, c.addtime desc)
union all
(select * from Table_Teacher as c where c.state in(1,2,10) and c.addby='chris' and c.location in
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')
and (c.ets is null or c.ets not like '%es1%') order by c.state asc, c.addtime desc)
合并2个语句,和做数学题差不多,提取公因式,分拆,合集。
用union all 吧,如果要去掉重复的数据,就用union吧!