如何消除SQL中的重复计算?(How to eliminate duplicate calculation in SQL?)

编程入门 行业动态 更新时间:2024-10-28 10:36:55
如何消除SQL中的重复计算?(How to eliminate duplicate calculation in SQL?)

我有一个可以简化为的SQL:

SELECT * FROM table WHERE LOCATE( column, :keyword ) > 0 ORDER BY LOCATE( column, :keyword )

您可以看到“LOCATE(column,:keyword)”的副本。 有没有办法只计算一次?

I have a SQL that can be simplified to:

SELECT * FROM table WHERE LOCATE( column, :keyword ) > 0 ORDER BY LOCATE( column, :keyword )

You can see there is a duplicate of "LOCATE( column, :keyword )". Is there a way to calculate it only once ?

最满意答案

HAVING在MySQL中使用别名:

SELECT *, LOCATE( column, :keyword ) AS somelabel FROM table HAVING somelabel > 0 ORDER BY somelabel

HAVING works with aliases in MySQL:

SELECT *, LOCATE( column, :keyword ) AS somelabel FROM table HAVING somelabel > 0 ORDER BY somelabel

更多推荐

本文发布于:2023-07-28 23:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310193.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:eliminate   SQL   calculation   duplicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!