新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
父子分類關(guān)系查詢使用的SQL語句介紹
SQL數(shù)據(jù)庫中,如果需要查詢父子分類關(guān)系,使用SQL語句應(yīng)該如何實(shí)現(xiàn)呢?下面就將為您介紹父子分類關(guān)系查詢使用的SQL語句的寫法,供您參考。

10年積累的網(wǎng)站制作、網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先建設(shè)網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有龍圩免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
例子如下圖:
查詢出來的結(jié)果多加一列,這一列的值為,當(dāng)icode_ind有子分類,則該列的值為1,否則為0。是否有子類,看一下那表就很明顯我的規(guī)則了。
實(shí)現(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
網(wǎng)站欄目:父子分類關(guān)系查詢使用的SQL語句介紹
瀏覽地址:http://fisionsoft.com.cn/article/dheigdh.html


咨詢
建站咨詢
