我有以下查询,想要对$find
name_re_all
中的每个值进行处理,我的查询中有哪些?
例如: name_re_all
如下:
ROW 3:
11111 22222 33333 44444
ROW 2:
55555 66666 77777
ROW 1:
88888 99999 112233 445566
如果值$find
为11111
,则显示所有值第3行:11111 22222 33333 44444
或
如果值$find
为66666
,则显示所有值第2行:55555 66666 77777
或
如果值$find
为33333
,则显示所有值第3行:11111 22222 33333 44444
或
如果值$find
为778899
,则显示所有值第1行:88888 99999 112233 445566
或
和...
$query = $this -> db -> query('
SELECT
@rownum := @rownum + 1 rownum,
tour_foreign.id,
tour_foreign.name,
tour_foreign.airline,
MIN(tour_foreign_residence.name_re) AS name_re,
tour_foreign.service,
tour_foreign.date_go,
tour_foreign.date_back,
tour_foreign.term,
tour_foreign.useradmin_submit,
tour_foreign.date_submit,
GROUP_CONCAT( tour_foreign_residence.name_re
ORDER BY tour_foreign_residence.name_re
SEPARATOR "، "
) AS name_re_all
FROM tour_foreign
INNER JOIN tour_foreign_residence
ON ( tour_foreign.id = tour_foreign_residence.relation )
JOIN (SELECT @rownum := 0) r
WHERE tour_foreign.name LIKE "%' . $find . '%"
GROUP BY tour_foreign.id
HAVING name_re_all LIKE "%' . $find . '%"'
);
我在数据库中的表:
答案 0 :(得分:0)
作为变体:将此查询包装到子查询 -
SELECT * FROM (
your query...
) t
WHERE FIND_IN_SET('11111', name_re_all);
修改强> 你应该使用子查询!
SELECT * FROM (
SELECT
@rownum := @rownum + 1 rownum,
...
...
...
GROUP_CONCAT( tour_foreign_residence.name_re
ORDER BY tour_foreign_residence.name_re
SEPARATOR "، "
) AS name_re_all
FROM tour_foreign
INNER JOIN tour_foreign_residence
ON ( tour_foreign.id = tour_foreign_residence.relation )
JOIN (SELECT @rownum := 0) r
WHERE tour_foreign.name LIKE "%' . $find . '%"
GROUP BY tour_foreign.id
-- HAVING name_re_all LIKE "%' . $find . '%"
) t
WHERE FIND_IN_SET('11111', name_re_all)