帮我优化这条sql语句,查询速度太慢
发布网友
发布时间:2024-10-18 03:25
我来回答
共1个回答
热心网友
时间:2024-11-17 04:24
测试下 应该能适用于 MSSql 2008及以上版本 或oracle
With ProctNameTable as
select ProctName, Code from Proct
SELECT [id]
,[NO]
,[Tag]
,[detectorTag]
,[result]
,[clean]
,(select ProctName from ProctNameTable where Code= [qingjieCode]) as qingjie
,(select ProctName from ProctNameTable where Code= [shuangfuCode]) as shuangfu
,(select ProctName from ProctNameTable where Code= [penwuCode]) as penwu
,(select ProctName from ProctNameTable where Code= [mianshuangruyeCode]) as yanshuang
,(select ProctName from ProctNameTable where Code= [mianshuangruyeCode2])as mianshuangruye1
,(select ProctName from ProctNameTable where Code= [mianshuangruyeCode3])as mianshuangruye2
,(select ProctName from ProctNameTable where Code= [mianshuangruyeCode4])as mianshuangruye3
,(select ProctName from ProctNameTable where Code= [jinghuaCode]) as jinghua
,(select ProctName from ProctNameTable where Code= [mianmoCode]) as mianmo
,(select ProctName from ProctNameTable where Code= [geliCode]) as geli
,(select ProctName from ProctNameTable where Code= [fendiBBCode]) as fendiBB
,(select ProctName from ProctNameTable where Code= [fendiBBCode2]) as fendiBB2
,(select ProctName from ProctNameTable where Code= [teshuhuliCode]) as teshuhuli
,(select ProctName from ProctNameTable where Code= [fangshaiCode]) as fangshai
,(select ProctName from ProctNameTable where Code= [fangshaiCode2]) as fangshai2
FROM [weizi].[dbo].[VICHY_Diagnosis_Result_Description] where Tag='D''P'
追问with的作用是能提速?
追答with的作用是先吧需要读的数据读进内存,这样就不用重复访问了