gpt4 book ai didi

PHP MySQL - IN/ALL/ANY 子查询中的列 'id' 不明确

转载 作者:行者123 更新时间:2023-12-01 00:05:15 24 4
gpt4 key购买 nike

我目前有以下查询工作:

$sql = $db->Query("SELECT a.id FROM surf a LEFT JOIN users b ON b.id = a.user LEFT JOIN surfed c ON c.user = '".$data['id']."' AND c.site = a.id WHERE a.active = '0' AND (b.coins >= a.cpc AND a.cpc >= '2') AND (c.site IS NULL AND a.user !='".$data['id']."')".$dbt_value." ORDER BY a.cpc DESC LIMIT 1");

但我想在其中添加以下 AND 语句:

 AND `cpc`<='10' AND (`id` NOT IN (SELECT `site` FROM `surfed_site`)) 

所以我让它看起来像:

$sql = $db->Query("SELECT a.id FROM surf a LEFT JOIN users b ON b.id = a.user LEFT JOIN surfed c ON c.user = '".$data['id']."' AND c.site = a.id WHERE a.active = '0' AND (b.coins >= a.cpc AND a.cpc >= '2') AND `cpc`<='10' AND (`id` NOT IN (SELECT `site` FROM `surfed_site`)) AND (c.site IS NULL AND a.user !='".$data['id']."')".$dbt_value." ORDER BY a.cpc DESC LIMIT 1");

但随后我收到此消息:

IN/ALL/ANY 子查询中的“id”列不明确

我的查询有什么问题?

最佳答案

尝试改变

AND `cpc`<='10' AND (`id` NOT IN (SELECT `site` FROM `surfed_site`)) 

AND `cpc`<='10' AND (`a.id` NOT IN (SELECT `site` FROM `surfed_site`)) 

您需要 a.id,因为它不确定要引用哪个表中的哪个 id 列。

关于PHP MySQL - IN/ALL/ANY 子查询中的列 'id' 不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15042296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com