SQL查询语句-返回名称的分类

 1:   
 2:   
 3:   
 4:  ---已?知?异?名?的?parent_id查?询?其?分?类?
 5:  SELECT  id ,
 6:          name_string ,
 7:          parent_id ,
 8:          name_state ,
 9:          published_year ,
10:          ( SELECT    COUNT(*)
11:            FROM      dbo.names
12:            WHERE     parent_id = n.id
13:          ) AS childnodecount
14:  FROM    dbo.names AS n
15:  WHERE   n.parent_id = 37388
16:  UNION
17:  ( SELECT    id ,
18:              name_string ,
19:              parent_id ,
20:              name_state ,
21:              published_year ,
22:              ( SELECT    COUNT(*)
23:                FROM      dbo.names
24:              )
25:    FROM      dbo.names
26:    WHERE     id = 37388
27:  )
28:  ORDER BY name_state ,
29:          published_year
30:   
31:   
32:  ---已?知?接?受?名?的?id,?查?询?其?分?类?
33:  SELECT  id ,
34:          parent_id ,
35:          name_string ,
36:          name_state ,
37:          published_year
38:  FROM    dbo.names
39:  WHERE   id = 37388
40:  UNION
41:  ( SELECT    id ,
42:              parent_id ,
43:              name_string ,
44:              name_state ,
45:              published_year
46:    FROM      dbo.names
47:    WHERE     parent_id = 37388
48:  )
49:  ORDER BY name_state ,
50:          published_year
51:   
52:   
53:   

转载于:https://www.cnblogs.com/apiaceae/archive/2010/02/28/1675055.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值