从对SQL结果去针对SQL语句进行排序
我有5条SQL语句...
比如SQL1,SQL2,SQL3,SQL4,SQL5
利用ADO查询出来.SQL1记录为20条,SQL2记录为2条,SQL3记录为50条,SQL4记录为7条,SQL5记录为3条
现在,我在一条总SQL语句中需要对着几条SQL进行排序.
select * from (SQL3) a left outer join (SQL2) b on XX=XX left outer join (SQL5) c on xx= xx left outer (...)
就是说,我总SQL语句里有5个空,要分别填入这5条SQL语句,这5条SQL语句的排序应该是记录数最大的排在第一个(如例句中的SQL3记录为50条),记录数最小的排在第二个(如例句中SQL2记录为2条),然后按升序排列(如例句中SQL5记录数排在第二).不排除有记录数相等的SQL语句.记录数如果相同,则可以不理会排列顺序.
我该如何操作?求个思路..谢谢...
另外,大家国庆快乐..中秋快乐...
送上66分,祝大家66大顺..
[解决办法]
[解决办法]
不知楼主的意思 是不是这样
我自己建了一个表。可能言不达意。
表111
id 字段
1 a
2 a
3 b
4 b
5 b
6 c
7 d
8 d
9 d
10 d
select * from
(
select a,COUNT(a) b from dbo.[111] where 字段 = 'a' group by a
union all
select a,COUNT(a) b from dbo.[111] where 字段 = 'b' group by a
union all
select a,COUNT(a) b from dbo.[111] where 字段 = 'c' group by a
union all
select a,COUNT(a) b from dbo.[111] where 字段 = 'd' group by a ) p order by b
其中
select a,COUNT(a) b from dbo.[111] where 字段 = 'a' group by a
select a,COUNT(a) b from dbo.[111] where 字段 = 'b' group by a
select a,COUNT(a) b from dbo.[111] where 字段 = 'c' group by a
select a,COUNT(a) b from dbo.[111] where 字段 = 'd' group by a
为你要的5条SQL语句
类似你应该可以举一反三
[解决办法]
上面写错了
select * from
(
select a,COUNT(a) b from dbo.[111] where 字段 = 'a' group by 字段
union all
select a,COUNT(a) b from dbo.[111] where 字段 = 'b' group by 字段
union all
select a,COUNT(a) b from dbo.[111] where 字段 = 'c' group by 字段
union all
select a,COUNT(a) b from dbo.[111] where 字段 = 'd' group by 字段 ) p order by b
[解决办法]
可以先把结果放到临时表,在临时表里排序