我有一个 MySQL 查询,它是这样的:
select
*,
(select meta_value
from nord_usermeta m
where meta_key = 'firm' and user_id = s.user_id
limit 1)
as firm,
(select meta_value f
rom nord_usermeta m
where meta_key = 'first_name' and user_id = s.user_id
limit 1)
as first_name,
(select meta_value
from nord_usermeta m
where meta_key = 'last_name' and user_id = s.user_id
limit 1)
as last_name
from nord_submissions s
order by created_at desc
现在我需要使用这样的 where 子句来缩小范围:
select
*,
(select meta_value
from nord_usermeta m
where meta_key = 'firm' and user_id = s.user_id
limit 1)
as firm,
(select meta_value
from nord_usermeta m
where meta_key = 'first_name' and user_id = s.user_id
limit 1)
as first_name,
(select meta_value
from nord_usermeta m
where meta_key = 'last_name' and user_id = s.user_id
limit 1)
as last_name
from nord_submissions s
where firm like '%DG%'
order by created_at desc
问题显然出在我使用子查询的方式上,但我找不到在 where 子句中引用它的方法。
请帮忙。