在 SQLite 中存储经常查询的列的方法?

发布于 2024-11-19 14:01:30 字数 429 浏览 4 评论 0原文

我有一个查询,涉及连续多次查找响应时间,如下所示:

ROUND(AVG(T.FinishTime-T.StartTime),3) AS 'Average', MAX(T.FinishTime-T.StartTime) AS 'Max', MIN(T.FinishTime-T.StartTime)

现在,我不完全理解 SQL 如何在后台处理这些东西,但从我对编码的一般知识来看,这样不是更好吗?减法T.FinishTime-T.StartTime效率更高?即计算可以完成一次,然后在该计算列表中找到聚合吗?或者已经这样做了?我只是想尝试将查询分解为更高效和可读的块。我一开始以为可以创建一个 T.FinishTime-T.StartTime 视图,并对此进行聚合,但后来我读到,每次使用视图时仍然会进行计算。

帮助表示赞赏!

I have a query that involves finding response times several times in a row, like so:

ROUND(AVG(T.FinishTime-T.StartTime),3) AS 'Average', MAX(T.FinishTime-T.StartTime) AS 'Max', MIN(T.FinishTime-T.StartTime)

Now, I don't fully understand how SQL processes this stuff in the background, but from my general knowledge of coding, is it not better to make the subtraction T.FinishTime-T.StartTime more efficient? i.e. can the calculation be done once and then the aggregates found on that list of calculations? Or is it already done this way? I just want to try and cut my queries down into more efficient and readable chunks. I thought at first a view of T.FinishTime-T.StartTime could be made and that aggregates carried out on this, but then I read that views still calculate each time they are used.

Help appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的好友蓝忘机已上羡 2024-11-26 14:01:30

您认为为什么计算如此简单的表达式会显着减慢您的应用程序的速度?

他们说,过早的优化是万恶之源。你可能把时间浪费在完全没有效果的事情上。首先进行配置,然后进行优化。如果您不分析,就不要优化,就这样。

Why do you think that calculation such a simple expression slows down your application by any significant amount?

Premature optimization is the root of all evil, they say. You may be wasting your time on something completely ineffectual. Profile first, optimize later. If you don't profile, don't optimize, period.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文