我有一个有国家,城市和大陆地区的桌子。
当一些人搜索一个家时,如果他输入例如“rom”我想要返回
我该怎么做?
修改 使用此处的搜索表单http://www.holiday-rentals.co.uk/查看我的意思
修改 这是我到目前为止所尝试的
SELECT DISTINCT COUNT(country),COUNT(city),COUNT(continent) FROM homes WHERE country LIKE '%rom%' OR city LIKE '%rom%' OR continent LIKE '%rom%';
提前致谢
答案 0 :(得分:1)
增强列文的答案:
SELECT 'city' AS result_type
, city
, COUNT(*) AS cnt
FROM homes
WHERE city LIKE '%rom%'
GROUP BY city
UNION ALL
SELECT 'country' AS result_type
, country
, COUNT(*) AS cnt
FROM homes
WHERE country LIKE '%rom%'
GROUP BY country
UNION ALL
SELECT 'continent' AS result_type
, continent
, COUNT(*) AS cnt
FROM homes
WHERE continent LIKE '%rom%'
GROUP BY continent