SQL问题(100分)

  • 主题发起人 主题发起人 superong
  • 开始时间 开始时间
S

superong

Unregistered / Unconfirmed
GUEST, unregistred user!
有一张表,表结构例如:Bh,ParnetID,A,B,C,D;Bh是主键,Parent,A,B三个条件可以决定一条记录.现在问题如下:<br>&nbsp; BH &nbsp; ParentID &nbsp; &nbsp; A &nbsp; &nbsp; B &nbsp; &nbsp; <br>&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"bb" &nbsp; <br>&nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"cc"<br>&nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"bb"<br>&nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"cc"<br><br>如何写出效率较高的SQL语句得出结果为<br><br>&nbsp; BH &nbsp; ParentID &nbsp; &nbsp; A &nbsp; &nbsp; B &nbsp; &nbsp; <br>&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"bb" &nbsp; <br>&nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"bb"<br>&nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"cc"<br>&nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp;"aa" &nbsp;"cc"
 
select * from table_name order by a,b
 
这是干啥呢
 
不行的,这种排序的位置可能会混乱了,两条相同的时候BH小的一定要排前面了.
 
应该是ParentID小的排在前面.
 
你是问问题还是脑筋急转弯啊?问题都没说明白啥意思。
 
select * from table_name order by a,b,ParentID
 
已经解决了,谢谢各位。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部