在合并结果集的时候出现了一些问题,请各位高手帮忙解决一下cp表的内容如下 id names
1 AA
2 BB
3 CC
4 DD
5 AB
6 AC现在想将两条查询语句查询出来的结果集合并在一起,查询语句如下
select * from cp where names like '%A%' order by id desc
select * from cp order by id desc想要的结果如下
id names
6 AC
5 AB
1 AA
6 AC
5 AB
4 DD
3 CC
2 BB
1 AA请问要怎么做啊
1 AA
2 BB
3 CC
4 DD
5 AB
6 AC现在想将两条查询语句查询出来的结果集合并在一起,查询语句如下
select * from cp where names like '%A%' order by id desc
select * from cp order by id desc想要的结果如下
id names
6 AC
5 AB
1 AA
6 AC
5 AB
4 DD
3 CC
2 BB
1 AA请问要怎么做啊
解决方案 »
- 表的列A是字符串类型,如何求该列字符串中的最大者,sql语句如何写。
- 表换成视图,报错
- SQL Server特殊字符的like查询
- SQL存储过程问题
- access连接到sql server的ODBC错误问题
- 如何在查询结果中加入一行平均值?
- 求助一条SQL语句?再线等待
- 用查询分析器拷贝一个表,对你来说太简单了,帮帮忙!
- 请问有没什么办法能够不通过sql server manager 来查看某一存储过程的源代码
- 如何利用MSDE2000+InstallShield Developer 把SQL安装程序集合到自己开发的程序中?
- 算法!这样的算法如何算?
- 求:根据一个商品的出库数量,来求这笔出库和哪几笔入库记录相关(先进先出)?
select * from cp where names like '%A%' order by id desc
UNION ALL
select * from cp order by id desc
UNION ALL
select * from cp order by id desc
insert into a values(1 , 'AA')
insert into a values(2 , 'BB')
insert into a values(3 , 'CC')
insert into a values(4 , 'DD')
insert into a values(5 , 'AB')
insert into a values(6 , 'AC') select id , names from
(
select * , px = 1 from a where names like '%A%'
union all
select * , px = 2 from a
) t
order by px , id desc
drop table a/*
id names
----------- ----------
6 AC
5 AB
1 AA
6 AC
5 AB
4 DD
3 CC
2 BB
1 AA(所影响的行数为 9 行)
*/
union all
select * ,0 as cnt from cp
order by cnt desc, id desc
union all
select * , px = 2 from a
order by px , id desc