本文介绍了如何消除SQL中的重复计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可以简化为的 SQL:
I have a SQL that can be simplified to:
SELECT *
FROM table
WHERE LOCATE( column, :keyword ) > 0
ORDER BY LOCATE( column, :keyword )
您可以看到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 中使用别名:
HAVING works with aliases in MySQL:
SELECT *, LOCATE( column, :keyword ) AS somelabel
FROM table
HAVING somelabel > 0
ORDER BY somelabel
这篇关于如何消除SQL中的重复计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!