sql排序问题
ID b c d
1 x h 1
2 y j 2
3 z k 1
4 a x 2
5 b y 1
如何让
ID B H D
2 Y J 2
3 Z K 1
这两条记录 总在记录的最下面 而且显示顺序为(只能按d排列 不能按id排列)
ID B H D
3 Z K 1
2 Y J 2
SQL code:
select * from tb order by case id when 2 then 2 when 3 then 3 else 1 end , id , d desc
SQL code:
create table tb(ID int, b varchar(10), c varchar(10), d int)
insert into tb values(1 , 'x' , 'h' , 1 )
insert into tb values(2 , 'y' , 'j' , 2 )
insert into tb values(3 , 'z' , 'k' , 1 )
insert into tb values(4 , 'a' , 'x' , 2 )
insert into tb values(5 , 'b' , 'y' , 1 )
go
select * from tb order by case id when 2 then 2 when 3 then 3 else 1 end , id , d desc
drop table tb
/*
ID b c d
----------- ---------- ---------- -----------
1
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
请问一下,外网两台SQLSERVER实例数据传输,有没有采用数据压缩和加密。压缩比是多少,加密是什么加密算法?相关文档哪里可以找到?谢谢
我也想知道!关注此贴!
关注~~
数据库大牛都哪去了啊?
......
有两个同样的表结构
表结构如下:
id(序号) parentid (父结点序号) name(结点名称)
表1 记录 1 0 aaa
2 ......
大家好,我最近维护一个项目,100多个表
只能用jdbc直连
遇到了多个表 关联 查询的情况 请大家指教
比如
student(studentid,classid)
class(classid,classname)
class_teacher(classid,teacherid)这个是中间表 ......
如下2张表:
table1:
node_id
parent_id
root_id
value
table2:
node_id
status
表1存储了一棵树,表2存储了节点状态,问题如下:
如何用SQL语句获得状态status为1的节点的所有子节点以及其下子树中所有节 ......