我需要改善大型MySQL视图的性能。其中大部分非常简单,不会造成太多的性能问题,但是有很长一段时间充满了数十个子查询,这些子查询以相同的问题递增一个值。我认为必须有更好的方法来做到这一点,但我不是SQL大师。任何帮助是极大的赞赏!如何减少对这些MySQL子查询的需求?
(我概括一下代码,使问题更加清晰)
SELECT
p.something,
p.otherthing,
c.athing,
d.nothing,
(select startdate from dbo.aqcprojects where projectid = p.id and aqcphase = 1) as 'Phase 1 start',
(select finishdate from dbo.aqcprojects where projectid = p.id and aqcphase = 1) as 'Phase 1 end',
(select startdate from dbo.aqcprojects where projectid = p.id and aqcphase = 2) as 'Phase 2 start',
(select finishdate from dbo.aqcprojects where projectid = p.id and aqcphase = 2) as 'Phase 2 end',
**the above four lines repeated ad nauseum.
FROM
bunch of joins
可以显示表结构将它添加到一堆? –