如何消除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 somelabelHAVING works with aliases in MySQL:
SELECT *, LOCATE( column, :keyword ) AS somelabel FROM table HAVING somelabel > 0 ORDER BY somelabel更多推荐
发布评论