落伍者站长论坛's Archiver

默飞 发表于 2008-6-1 14:21

SQL语句组合问题,分组查询。

SQL语句组合问题,分组查询。
select top 10 id from #C where C=1,
select top 10 id from #C where C=2,
可以组合成一句SQL,但功能不能减,么?

dj0596 发表于 2008-6-1 14:32

你太强了,没语言说你

蒋廷伟 发表于 2008-6-1 14:43

select top 10 id from #C where C=1 and C=2

=1 =2的一起查


select top 10 id from #C where C=1 or C=2

这个也一样。。

默飞 发表于 2008-6-1 21:19

这样可以都TOP 10了?

goffice 发表于 2008-6-2 10:32

[quote]原帖由 [i]默飞[/i] 于 2008-6-1 14:21 发表 [url=http://www.im286.com/redirect.php?goto=findpost&pid=26633871&ptid=2627117][img]http://www.im286.com/images/common/back.gif[/img][/url]
SQL语句组合问题,分组查询。
select top 10 id from #C where C=1,
select top 10 id from #C where C=2,
可以组合成一句SQL,但功能不能减,么? [/quote]

select top 10 id from #C where C=1 and c=2 是查不到东西的
select top 10 id from #C where C=1 or c=2  查到的东西又是混起来的
我看还是分开来操作比较合适。

zhyu 发表于 2008-6-2 11:02

select * from #C where id in(select top 10 id from #C where C=1,select top 10 id from #C where C=2)

这样试试吧,,,我没测试

39cool 发表于 2008-6-2 14:44

很简单[code]select top 10 id from #C where C=1
union
select top 10 id from #C where C=2
order by C
[/code]

孟祥彬 发表于 2008-6-2 18:12

楼主在学#C 吗

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.