iT邦幫忙

0

請問同一個talbe顥示階層大的處名稱, SQL指令該如何寫?

XYZ 2021-09-13 15:23:23878 瀏覽
  • 分享至 

  • xImage

請問同一個talbe顥示階層大的處名稱, SQL指令該如何寫?
更正~希望能像TABLE C的結果,TABLE C 的處名稱table:A欄位階層='2'
https://ithelp.ithome.com.tw/upload/images/20210913/20108157EianaslHNm.jpg

https://ithelp.ithome.com.tw/upload/images/20210913/20108157Y5QjfTQowC.jpg

https://ithelp.ithome.com.tw/upload/images/20210913/20108157gjxYo5gJzp.jpg

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
1
bachikevin
iT邦新手 5 級 ‧ 2021-09-13 16:13:39
最佳解答
select C.處代號, C.處名稱 as N'單位名稱', C.單位代號, C.單位名稱, B.訂單編號
from 
    (select A.處代號, innA.單位名稱 as N'處名稱', A.單位代號, A.單位名稱
    from A
    left join A as innA
    on A.處代號 = innA.處代號
    where A.階層 = 3 AND innA.階層 = 2) as C
join B
on C.單位代號 = B.單位代號
order by B.訂單編號
0
Yaowen
iT邦研究生 4 級 ‧ 2021-09-13 15:50:57
select A.處代號,A.單位名稱,A.單位代號.A.單位名稱 ,B.訂單編號 from tableA A
inner join tableB B
on A.單位代號 = B.單位代號
order by A.單位代號 ASC

order by用法
Desc 大到小
ASC 小大到

1
緯大啊緯大人
iT邦研究生 1 級 ‧ 2021-09-14 08:34:54

這資料表設計沒問題嗎...? 總覺得哪裡怪怪的XD
感覺應該有個處理 【處】的表~
照現有資料表邏輯,好像只能針對=2 或者是同一處,min(階層)的方向來處理了

我要發表回答

立即登入回答