高分求购sql语句

HndyLiu 2003-11-19 03:18:59
表table
子段:id pid morder
1 0 1
2 1 1
3 1 2
4 0 2
5 0 3

需求:从表table里读出pid=0的所有记录,并且将所有pid=id.value全部读取出来,并按照morder排序
...全文
20 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
monkeys 2003-11-19
  • 打赏
  • 举报
回复
select * from table order by pid,id
wzh1215 2003-11-19
  • 打赏
  • 举报
回复
没有问题,有问题就可能是类型的问题了!
create table #table(id int,pid int,morder int)
insert #table values(1,0,1)
insert #table values(2,1,1)
insert #table values(3,1,2)
insert #table values(4,0,2)
insert #table values(5,0,3)

select * from #table where pid=0
union all
select * from #table where pid=id
order by morder
HndyLiu 2003-11-19
  • 打赏
  • 举报
回复

谢谢大家,

wzh1215(四脚蛇) ( )

select * from table where pid=0
union all
select * from table where pid=id
order by morder

语句报错:=号附近有语法错误
wzh1215 2003-11-19
  • 打赏
  • 举报
回复
select * from table where pid=0
union all
select * from table where pid=id
order by morder
HndyLiu 2003-11-19
  • 打赏
  • 举报
回复
对啊
pid=0为主力
pid=id的值的为 它的替补
现在需要:将主力提取,并将它对应的替补放在它随后
brook_huang 2003-11-19
  • 打赏
  • 举报
回复
select * from table wher pid<>0
brook_huang 2003-11-19
  • 打赏
  • 举报
回复
pid=id.value?
select * from table wher pid=0 order by morder
sunshareforever 2003-11-19
  • 打赏
  • 举报
回复
select * from table where id = pid and pid = '0' order by morder

HndyLiu 2003-11-19
  • 打赏
  • 举报
回复
读取所有PID=0的记录:select * from table wher pid=0

读取所有PID记录不为0的记录
HndyLiu 2003-11-19
  • 打赏
  • 举报
回复
select * from table wher pid=0

select * from where pid in (select * from table wher pid=0)
zjcxc 2003-11-19
  • 打赏
  • 举报
回复
--什么意思?
select * from table wher pid=0

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧