我有以下SQL查询,我希望将public.account.phone_number
的值用于子查询的LIKE子句。
不幸的是,当我替换数据库中的电话号码total_responses
'%public.account.phone_number'
时查询为SELECT
public.email_account.email,
public.account.password,
public.ad.city,
public.ad.state,
public.ad.age,
public.ad.hotel,
public.ad.insert_time,
public.ad.ad_url,
public.ad.active,
public.ad.on_page,
public.ad.paid,
public.account.phone_number,
(SELECT COUNT(*) FROM public.match where match_id LIKE '%public.account.phone_number') AS total_responses
FROM
public.account
INNER JOIN public.ad
ON public.account.id = public.ad.account_id
INNER JOIN public.email_account
ON public.account.email_account_id = public.email_account.id
ORDER BY
ad.active ASC,
on_page DESC
返回0时,某些内容无法正常工作。
<input type="checkbox" id="situationcontrol" name="situationcontrol">
答案 0 :(得分:1)
我猜你想要与外部字段phone_number进行连接。
试试这个:
SELECT
public.email_account.email,
public.account.password,
public.ad.city,
public.ad.state,
public.ad.age,
public.ad.hotel,
public.ad.insert_time,
public.ad.ad_url,
public.ad.active,
public.ad.on_page,
public.ad.paid,
public.account.phone_number,
(SELECT COUNT(*) FROM public.match where match_id LIKE '%' || public.account.phone_number) AS total_responses
FROM
public.account
INNER JOIN public.ad
ON public.account.id = public.ad.account_id
INNER JOIN public.email_account
ON public.account.email_account_id = public.email_account.id
ORDER BY
ad.active ASC,
on_page DESC