作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我进行了一个查询,使用它创建了一个变量 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/
我是一名优秀的程序员,十分优秀!