Questions tagged «subquery»

SQL术语,用于描述何时将SELECT语句用作较大SQL语句的一部分。较大的语句可能是DML,并且总是在方括号或括号中找到。

2
使用COALESCE(…)优化子查询的选择
我在应用程序中使用的视图很大。我认为我已经缩小了性能问题,但是不确定如何解决。视图的简化版本如下所示: SELECT ISNULL(SEId + '-' + PEId, '0-0') AS Id, *, DATEADD(minute, Duration, EventTime) AS EventEndTime FROM ( SELECT se.SEId, pe.PEId, COALESCE(pe.StaffName, se.StaffName) AS StaffName, -- << Problem! COALESCE(pe.EventTime, se.EventTime) AS EventTime, COALESCE(pe.EventType, se.EventType) AS EventType, COALESCE(pe.Duration, se.Duration) AS Duration, COALESCE(pe.Data, se.Data) AS Data, COALESCE(pe.Field, se.Field) AS Field, pe.ThisThing, se.OtherThing …

4
MySQL子查询速度大大降低,但它们独立运行良好
查询1: select distinct email from mybigtable where account_id=345 需要0.1秒 查询2: Select count(*) as total from mybigtable where account_id=123 and email IN (<include all from above result>) 需要0.2秒 查询3: Select count(*) as total from mybigtable where account_id=123 and email IN (select distinct email from mybigtable where account_id=345) 花费22分钟和90%的时间处于“准备”状态。为什么要花这么多时间。 表是在MySQL 5.0上具有320万行的innodb
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.