一个简单的sql实例:
我输入一下代码可得一下结果:
select*from module3
union
select*from module2
union
select*from module1
no Ph V time level
1 6.3 10m/s 2008-06-10 20:32:56.390 standard
1 6.5 10m/s 2008-06-10 17:46:51.437 a
1 6.5 10m/s 2008-06-10 21:01:02.013 b
2 6.3 10m/s 2008-06-10 20:32:57.247 standard
2 6.5 10m/s 2008-06-10 17:47:04.403 a
2 6.5 10m/s 2008-06-10 21:01:05.250 b
3 6.3 10m/s 2008-06-10 20:32:57.750 standard
3 6.5 10m/s 2008-06-10 17:49:53.513 b
3 6.5 10m/s 2008-06-10 21:01:06.937 b
我变了一下代码,想让no=1的三行列出来
select*from module3
union
select*from module2
union
select*from module1
where no=1
结果确是:
№ ph v time level
1 6.3 10m/s 2008-06-10 20:32:56.390 standard
1 6.5 10m/s 2008-06-10 17:46:51.437 a
1 6.5 10m/s 2008-06-10 21:01:02.013 b
2 6.3 10m/s 2008-06-10 20:32:57.247 standard
2 6.5 10m/s 2008-06-10 21:01:05.250 b
3 6.3 10m/s 2008-06-10 20:32:57.750 standard
3 6.5 10m/s 2008-06-10 21:01:06.937 b
请问大家怎么才能达到我要的结果?谢谢了
我输入一下代码可得一下结果:
select*from module3
union
select*from module2
union
select*from module1
no Ph V time level
1 6.3 10m/s 2008-06-10 20:32:56.390 standard
1 6.5 10m/s 2008-06-10 17:46:51.437 a
1 6.5 10m/s 2008-06-10 21:01:02.013 b
2 6.3 10m/s 2008-06-10 20:32:57.247 standard
2 6.5 10m/s 2008-06-10 17:47:04.403 a
2 6.5 10m/s 2008-06-10 21:01:05.250 b
3 6.3 10m/s 2008-06-10 20:32:57.750 standard
3 6.5 10m/s 2008-06-10 17:49:53.513 b
3 6.5 10m/s 2008-06-10 21:01:06.937 b
我变了一下代码,想让no=1的三行列出来
select*from module3
union
select*from module2
union
select*from module1
where no=1
结果确是:
№ ph v time level
1 6.3 10m/s 2008-06-10 20:32:56.390 standard
1 6.5 10m/s 2008-06-10 17:46:51.437 a
1 6.5 10m/s 2008-06-10 21:01:02.013 b
2 6.3 10m/s 2008-06-10 20:32:57.247 standard
2 6.5 10m/s 2008-06-10 21:01:05.250 b
3 6.3 10m/s 2008-06-10 20:32:57.750 standard
3 6.5 10m/s 2008-06-10 21:01:06.937 b
请问大家怎么才能达到我要的结果?谢谢了
select*from module3
union
select*from module2
union
select*from module1) t
where no=1
select*from module3
union
select*from module2
union
select*from module1
)tbl
where tbl.no = 1
select*from module3 where ...
union
select*from module2 where ...
union
select*from module1 where ...
where no=1
union
select*from module2
where no=1
union
select*from module1
where no=1
where no=1
union
select*from module2
where no=1
union
select*from module1
where no=1 --or
select * from (
select * from module3
union
select * from module2
union
select * from module1
) aa
where no=1
select*from module3
union
select*from module2
union
select*from module1) t
where no=1
比较简单。
楼主sql的问题在于
where只是对最后一个select语句进行筛选,而不是对所有的select进行筛选