我有一个SQL,可以简化为:
SELECT * FROM table WHERE LOCATE( column, :keyword ) > 0 ORDER BY LOCATE( column, :keyword )
您会看到“ LOCATE(column,:keyword)”重复。有没有一种方法可以只计算一次?
HAVING在MySQL中可以使用别名:
SELECT *, LOCATE( column, :keyword ) AS somelabel FROM table HAVING somelabel > 0 ORDER BY somelabel