將一列分裂成四列,進行聯合查詢.

有些數據雜揉在一起,我們要將其一列分裂成四列,進行聯合查詢.如下查詢語句,將 B.Rssi這一列分爲RssiA,RssiB,RssiC,RssiD四列.使用join關鍵字進行聯合查詢.

select a.ID ID ,a.PX PX,a.PY PY,b.Rssi RssiA,c.Rssi RssiB,d.Rssi RssiC,e.Rssi RssiD
 from (SELECT BP.ID,SP.PX,SP.PY from StaticPrint as SP , BeaconPrint as BP where BP.ID=SP.ID) a  join 
(select B.Rssi,BP.ID from  Beacon as B,BeaconPrint as BP ,StaticPrint as SP where B.ID = BP.BID1 and BP.ID=SP.ID) b on a.ID=b.ID  join
(select B.Rssi,BP.ID from  Beacon as B,BeaconPrint as BP ,StaticPrint as SP where B.ID = BP.BID2 and BP.ID=SP.ID) c on a.ID=c.ID join
(select B.Rssi,BP.ID from  Beacon as B,BeaconPrint as BP ,StaticPrint as SP where B.ID = BP.BID3 and BP.ID=SP.ID) d on a.ID=d.ID join
(select B.Rssi,BP.ID from  Beacon as B,BeaconPrint as BP ,StaticPrint as SP where B.ID = BP.BID4 and BP.ID=SP.ID) e on a.ID=e.ID 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章