我已将以下查询转换为视图表名销售板:
select
distinct(p.paymentID) AS paymentID,
j.jobID AS jobID,j.jobNumber AS jobNumber,j.jobType AS jobType, j.countType AS countType, j.countID AS countID,
ui.userID AS salesRep,
(
case
when (j.idType = 'dealership') then d.dealershipName
when (j.idType = 'Group') then g.groupName
when (j.idType = 'Agency') then a.agencyName
end
) AS dealershipName,
(
case
when (p.manualTimestamp <> '0000-00-00 00:00:00') then p.manualTimestamp
when (p.manualTimestamp = '0000-00-00 00:00:00') then from_unixtime(p.timestamp)
end
) AS checkTS,
p.paymentAmount AS paymentAmount,
po.estimatedMailArrival AS estimatedMailArrival
from jobs j
left join smdealershipjoins smdj on j.dealershipID = smdj.dealership
left join smgroupjoins smgj on j.dealershipID = smgj.groupID
left join smagencyjoins smaj on j.dealershipID = smaj.agencyID
join userinfo ui on
(
case
when (j.idType = 'dealership') then (smdj.sm = ui.userID)
when (j.idType = 'Group') then (smgj.sm = ui.userID)
when (j.idType = 'Agency') then (smaj.sm = ui.userID)
end
)
left join dealerships d on smdj.dealership = d.dealershipID
left join dealershipgroups g on smgj.groupID = g.groupID
left join agencies a on smaj.agencyID = a.agencyID
join payments p on j.jobID = p.jobID
left join purchaseorders po on j.jobID = po.jobID
order by
(
case
when (p.manualTimestamp <> '0000-00-00 00:00:00') then p.manualTimestamp
when (p.manualTimestamp = '0000-00-00 00:00:00') then from_unixtime(p.timestamp)
end
) desc
视图保存并返回预期结果。但是,每当我在新视图表上运行最简单的查询时,查询都需要几分钟才能运行。我四处搜寻,看看是否有什么可以解决的 - 但我空手而归:(
有什么可以做的吗?我绞尽脑汁想寻求帮助。