我开始处理多年前使用ACCESS生成的旧数据库。所有查询都是使用ACCESS查询向导设计的,它们似乎非常耗时,我希望提高它们的性能。
所有查询都依赖于至少三个子查询,我想重写SQL代码以将它们转换为单个查询。
这里有一个我正在谈论的例子:
这是主要查询:
SELECT Subquery1.pid,Table4.SIB,Subquery1.event, Subquery1.event_date,Subquery2.GGG,Subquery3.status FROM Subquery1 LEFT JOIN((表4 LEFT JOIN Subquery2 ON Table4.SIB = Subquery2.SIB)LEFT JOIN Subquery3 ON Table4.SIB = Subquery3.SIB) ON Subquery1.pid = Table4.PID;
此主查询取决于三个子查询:
Subquery1
SELECT Table2.id,Table2.pid,Table2.npid,Table3.event_date, Table3.event,Table3.notes,Table2.other FROM Table2 INNER JOIN Table3 ON Table2.id = Table3.subject_id WHERE(((Table2.pid)不为空)AND ((Table3.event_date)> #XX / XX / XXXX#)AND((Table3.event)赞" * AAAA"或 (Table3.event)=" BBBB"))ORDER BY Table2.pid,Table3.event_date DESC;
Subquery2
SELECT Table1.SIB,IIf(Table1.GGG Like" AAA"," BBB",IIf(Table1.GGG) 喜欢" CCC"," BBB",IIf(Table1.GGG Like" DDD"," DDD"," EEE&#34 ;)))作为GGG FROM 表1;
Subquery3
SELECT Table5.SIB,Table5.PID,IIf(Table5.field1 Like " 1"," ZZZ",IIf(Table5.field1 Like" 2"," ZZZ",IIf(Table5.field1 Like) " 3"," ZZZ",IIf(Table5.field1 Like" 4"," HHH",IIf(Table5.field1赞 " 5"," HHH",IIf(Table5.field1 Like" 6"," HHH"," UUU" ))))))AS SSS FROM 表5;
这是提高此查询性能并将所有子查询转换为单个语句的最佳方法。
我可以处理每个子查询,但我很难将它们连接在一起。
有人能用这段代码帮我一点吗?
非常感谢,
最佳,
答案 0 :(得分:0)
如果:
Table5.field1="3"
实际上是如何编写一些子查询(没有实际的狂野字符),通过将其更改为
可以节省大量时间 /src/main/java