Questions tagged «query-refactor»

3
避免多个`或`表达式
我有以下oracle SQL及其工作原理,但与所有ors 比较难看。有更简洁的方法吗? SELECT * FROM foobar WHERE (SUBJECT ='STAT' and TERM ='111') or (SUBJECT ='STAT' and TERM ='222') or (SUBJECT ='ENGLISH' and TERM ='555') or (SUBJECT ='COMM' and TERM ='444') or (SUBJECT ='COMM' and TERM ='333') or (SUBJECT ='STAT' and TERM ='666') ...

3
这两个查询在逻辑上是否等效?
这两个查询在逻辑上是否等效? DECLARE @DateTime DATETIME = GETDATE() 查询1 SELECT * FROM MyTable WHERE Datediff(DAY, LogInsertTime, @DateTime) > 7 查询2 SELECT * FROM MyTable WHERE LogInsertTime < @DateTime - 7 如果它们在逻辑上不是等效的,您可以给我第一个查询的逻辑等效,以便WHERE子句可以有效地使用索引(即消除函数包装)吗?

2
是否可以通过重复TableB将TableA的每一行连接到较小的TableB的行,但是需要多次?
抱歉,标题令人困惑,我不确定在那里写什么。 我有一张有几百条记录的表。我需要将此表的每条记录分配给一个较小的动态用户表,并且用户应交替选择要分配的记录。 例如,如果TableA是 Row_Number()ID 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 并且TableB是 Row_Number()ID 1 1 2 2 3 3 我需要的最终结果是 用户编号RecordId 1 1 2 2 3 3 1 4 2 5 3 6 1 7 2 8 …
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.