我有这个 sql 命令:
SELECT RecordedBy as 'Recorded By', COUNT(*) Total
FROM mytable
WHERE
StartedDate BETWEEN DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), '00:01AM')
AND DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP), '11:59PM')
group by RecordedBy order by Total desc
我想要完成的是通过将此 sql 嵌入另一个而不更改原始 sql来进一步优化此查询的结果。
例如,我想通过 RecordedBy 子句缩小原始 sql 的范围:我想做的是:
select * from mytable in
(
SELECT RecordedBy as 'Recorded By', COUNT(*) Total FROM mytable
WHERE StartedDate BETWEEN
DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP),'00:01AM')
AND DATEADD(day, DATEDIFF(day, 0, CURRENT_TIMESTAMP),'11:59PM')
group by RecordedBy order by Total desc
)
但这当然会导致语法错误。谁能想到我现在缺少的东西?