1. 程式人生 > >sql查詢總記錄以及 查詢每條光纜下的所涉及到表的信息

sql查詢總記錄以及 查詢每條光纜下的所涉及到表的信息

進行 line 長度 產生 損壞 表關聯 conn sql查詢 cas

/*光纜有條少條隱患
1,查詢光纜表Optic_Cable,
2,根據光纜表關聯的光纜巡檢(軌跡巡檢)的路線查標石(Optic_LinePat軌跡的路線名稱),(Optic_LinePat_Sub,軌跡路線下的標石),
3,然後根據標石關聯巡檢信息表中這個標石的所有隱患次數(Optic_LinePat_Rec巡檢產生的信息表,根據上面查詢到的標石進行隱患匹配)
*/
select a.光纜條數 as glcount,a.光纜長度 as gllength,b.正常端口 as yesdk,b.損壞端口 as nodk,
b.業務已使用 as yesyew,b.業務未使用 as noyew,c.經過標石 as biaoshi,d.隱患 as yinhuan from
(select count(*)as ‘光纜條數‘, sum(CONVERT(int,cable_length)) as ‘光纜長度‘ from Optic_Cable) a,
(select COUNT(case status when ‘0‘ then ‘正常‘ end) as ‘正常端口‘,
COUNT(case status when ‘1‘ then ‘損壞‘ end) as ‘損壞端口‘,
COUNT(case when connect_content=‘‘ or connect_content is null then ‘未使用‘ end)‘業務未使用‘,
COUNT(case when connect_content is not null then ‘已使用‘ end)as ‘業務已使用‘
from Optic_Cable_Port ) b,
(select COUNT(c.F_Id) ‘經過標石‘from Optic_Cable a /*光纜*/
left join Optic_LinePat b/*光纜巡檢線路*/
on a.F_Id=b.F_Id
left join Optic_LinePat_Sub c/*光纜線路子表(標石)*/
on b.F_Id=c.F_Olp_Id
where b.F_Id is not null) c,
(select COUNT(*)as ‘隱患‘ from Optic_Cable a /*光纜*/
left join Optic_LinePat b/*光纜巡檢線路(光纜表中有個軌跡巡檢的名稱兩者進行關聯)*/
on a.F_Id=b.F_Id
left join Optic_LinePat_Sub c/*光纜線路子表(軌跡巡檢條數下有標石,在標石表中有軌跡的關聯編號)*/
on b.F_Id=c.F_Olp_Id
left join Optic_LinePat_Rec d/*在線路巡檢表中有標石的編號f_well_id*/
on c.F_Well_Id =d.F_well_id/*拿標石去查詢產生的隱患,兩者關聯*/
where b.F_Id is not null and d.F_Env_State=‘隱患‘)d

/**查詢總記錄**/
select a.glcount,a.gllength,b.duankouYes,b.duankouNo ,
b.yewuYes,b.yewuNo ,c.biaoshi ,d.隱患 as yinhuan from
(select count(*)as glcount, sum(CONVERT(int,cable_length)) as gllength from Optic_Cable) a,
(select COUNT(case status when ‘0‘ then ‘正常‘ end) as duankouYes,
COUNT(case status when ‘1‘ then ‘損壞‘ end) as duankouNo,
COUNT(case when connect_content=‘‘ or connect_content is null then ‘未使用‘ end)yewuNo,
COUNT(case when connect_content is not null then ‘已使用‘ end)as yewuYes
from Optic_Cable_Port ) b,

(select COUNT(c.F_Id) biaoshi from Optic_Cable a
left join Optic_LinePat b
on a.F_Id=b.F_Id
left join Optic_LinePat_Sub c
on b.F_Id=c.F_Olp_Id
where b.F_Id is not null) c,

(select COUNT(*)as ‘隱患‘ from Optic_Cable a
left join Optic_LinePat b
on a.F_Id=b.F_Id
left join Optic_LinePat_Sub c
on b.F_Id=c.F_Olp_Id
left join Optic_LinePat_Rec d
on c.F_Well_Id =d.F_well_id
where b.F_Id is not null and d.F_Env_State=‘隱患‘)d

sql查詢總記錄以及 查詢每條光纜下的所涉及到表的信息