0
我正在將我的存儲過程從Sql Server
遷移到MySql
。臨時表更新mysql
某處我正面臨着將更新查詢從MS sql server轉換爲Mysql臨時變量的問題。這裏是我的MS SQL Server查詢:
update sampleStoreTV set felony = c.fel,misdemeanor = c.mis,violation = c.vio
from (select srcCL.id as 'storeId',
case when SUM(case when srcCL.cl='FELONY' then 1 else 0 end)>0 then 1 else 0 end as 'fel',
case when SUM(case when srcCL.cl='MISDEMEANOR' then 1 else 0 end)>0 then 1 else 0 end as 'mis',
case when SUM(case when srcCL.cl='VIOLATION' then 1 else 0 end)>0 then 1 else 0 end as 'vio'
from
(select DM_Sample_Store.DM_Sample_Store_ID as 'id',
Charge_Level.Mapped_Charge_Level as 'cl'
from DM_Sample_Store
left join screening_result on Screening_Result.Screening_Result_id = DM_Sample_Store.Screening_Result_id
left join Crim_Case on Screening_Result.Screening_Result_id = Crim_Case.Screening_Result_id
left join Crim_Charge on Crim_Case.Crim_case_id = Crim_Charge.Crim_case_id
left join PDL_DataSource on DM_Sample_Store.DataSource_Id = PDL_DataSource.DataSource_Id
left join DM_Sample_Search_Param on DM_Sample_Store.DM_Sample_Store_ID = DM_Sample_Search_Param.DM_Sample_Store_ID
left join Charge_Level on Crim_Charge.Sanitized_Charge_Level_id = Charge_Level.Charge_Level_id
where PDL_DataSource.DataSource_Id = dataSourceId
and DM_Sample_Store.Active = 1
and DM_Sample_Search_Param.Global_Search_Parameter_ID in (sosGspId, freqGspId, clGspId, dtGspId)
and DM_Sample_Search_Param.Active = 1
-- and Crim_Charge.AOR_Days is not null
) srcCL
group by id
having SUM(case when cl='FELONY' then 1 else 0 end)>0
or SUM(case when cl='MISDEMEANOR' then 1 else 0 end)>0
or SUM(case when cl='VIOLATION' then 1 else 0 end)>0) c
where sampleId = c.storeId
感謝一噸:)它的工作 –