自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

父子分類關(guān)系查詢使用的SQL語句介紹

數(shù)據(jù)庫 SQL Server
SQL數(shù)據(jù)庫中,如果需要查詢父子分類關(guān)系,使用SQL語句應(yīng)該如何實現(xiàn)呢?下面就將為您介紹父子分類關(guān)系查詢使用的SQL語句的寫法,供您參考。

SQL數(shù)據(jù)庫中,如果需要查詢父子分類關(guān)系,使用SQL語句應(yīng)該如何實現(xiàn)呢?下面就將為您介紹父子分類關(guān)系查詢使用的SQL語句的寫法,供您參考。

例子如下圖:

  

查詢出來的結(jié)果多加一列,這一列的值為,當icode_ind有子分類,則該列的值為1,否則為0。是否有子類,看一下那表就很明顯我的規(guī)則了。

實現(xiàn)的SQL語句:

1.

select a.iCode_ind,a.icode,
case when b.iCode_ind is null then 0 else 1 end
from TabA a outer apply (select top 1 iCode_ind from TabA
where icode_ind like a.icode_ind+'%' and icode_ind<>a.icode_ind) b

2.

select *,case when exists(select 1 from tb
where iCode_ind<>t.iCode_ind
and iCode_ind like t.iCode_ind+'%')
then 1 else 0 end
from tb t

3.

select iCode_ind,icode,col=case when exists(select 1 from 表名 where iCode_ind like a.iCode_ind+'%' and iCode_ind!=a.iCode_ind) then 1 else 0 end
from 表名 a

 

 

 【編輯推薦】

SQL語句中output的用法

詳解SQL中的GROUP BY語句

sqlplus執(zhí)行存儲過程和sql語句的寫法

SQL Server日期計算語句

為您介紹一些不常見的SQL語句

 

責任編輯:段燃 來源: 博客園
相關(guān)推薦

2010-09-07 10:35:38

SQL語句

2010-10-27 15:11:52

oracle遞歸查詢

2023-11-14 10:03:30

數(shù)據(jù)庫技術(shù)

2010-11-12 14:10:15

SQL遍歷父子關(guān)系表

2010-07-08 13:26:02

SQL Server

2010-10-21 10:28:13

SQL Server查

2010-09-25 16:32:02

SQL語句

2010-10-27 10:11:07

Oracle分頁查詢

2023-03-31 14:15:57

SQLORDER BY

2010-03-15 19:11:39

Java多線程語句

2010-10-21 12:16:11

SQL Server查

2010-09-26 15:23:24

SQL語句

2010-09-08 17:10:24

SQL循環(huán)語句

2010-09-25 15:26:45

SQL查詢語句

2010-11-11 11:37:22

SQL SELECT語

2010-09-28 14:33:13

SQL語句

2010-11-12 13:40:38

動態(tài)sql語句

2010-10-22 15:52:41

SQL Server創(chuàng)

2017-09-07 16:20:39

SQL查詢語句查詢優(yōu)化

2019-11-06 09:30:35

SQL查詢語句數(shù)據(jù)庫
點贊
收藏

51CTO技術(shù)棧公眾號