gpt4 book ai didi

php - MySQL:使用 AS 变量进行查询不起作用

转载 作者:行者123 更新时间:2023-11-29 16:31:44 25 4
gpt4 key购买 nike

我进行了一个查询,使用它创建了一个变量 accountId,为什么我无法在子查询中重用 accountId?

这是我的代码:

SELECT userId AS accountId,
(SELECT recommended FROM ads_connections WHERE byUserId = accountId AND throughUserId = accountId AND adId = :recommendedAdId) AS recommended,
--
(SELECT requestStatus FROM ads_recommends_requests WHERE
userId = :currentUserId AND
requestFromUserId = accountId AND
advertisementId = :statusAdId) AS requestStatus,

(SELECT COUNT(id) FROM ads_recommends_requests
WHERE
requestFromUserId = accountId AND
advertisementId = :countAdId AND
requestStatus = '1'
) AS recommendedTimes
--
FROM user_contacts

WHERE userId IN " . $myCircleString . "
AND phoneNumber = :phoneNumber
AND (SELECT fictive FROM users WHERE id = userId) = 0
";

输出示例:

"data": [
{
"userId": 0,
"accountId": 2,
"fictive": false,
"name": "Mickael",
"phoneNumber": "0584688888",
"review": "0",
"liked": false,
"recommended": 0,
"requestStatus": 0,
"recommendedTimes": 0
}

谢谢

最佳答案

检查这个-

SELECT userId AS accountId,
(SELECT recommended FROM ads_connections WHERE byUserId = userId AND throughUserId = userId AND adId = :recommendedAdId) AS recommended,
--
(SELECT requestStatus FROM ads_recommends_requests WHERE
userId = :currentUserId AND
requestFromUserId = userId AND
advertisementId = :statusAdId) AS requestStatus,

(SELECT COUNT(id) FROM ads_recommends_requests
WHERE
requestFromUserId = userId AND
advertisementId = :countAdId AND
requestStatus = '1'
) AS recommendedTimes
--
FROM user_contacts

WHERE userId IN " . $myCircleString . "
AND phoneNumber = :phoneNumber
AND (SELECT fictive FROM users WHERE id = userId) = 0
";

关于php - MySQL:使用 AS 变量进行查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53812295/

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