【发布时间】:2013-06-17 21:58:48
【问题描述】:
现在我有以下 SQL:
select MAX(score) as score, title from
(
select 2 as score, title from tableName WHERE title LIKE '%railway employee%'
union
select 1 as score, title from tableName WHERE title LIKE '%railway%'
union
select 1 as score, title from tableName WHERE title LIKE '%employee%'
) as t1
group by title
order by score DESC
我希望能够做类似的事情:
select MAX(score) as score, title from
(
select LEN(CurrentTerm) as score, title from tableName WHERE title LIKE IN ('%railway employee%', '%railway%', '%employee%')
) as t1
group by title
order by score DESC
CurrentTerm 将是匹配项,而不是表中的列。 SQL 中是否有任何类似的东西,特别是 MySQL?
【问题讨论】:
-
我猜你可以用正则表达式代替
LIKE IN。 -
根据查询,数据库似乎缺乏正常性。更好的数据库结构可能是最好的解决方案。