我想检索具有特定值的行数,但该值取决于在使用此结果之前必须执行的查询
已知变量为 adId
,例如 adId
是32所以我想得到 requestFrom
哪里 adId = 32
容易的: $result = SELECT requestFrom FROM myTable WHERE adId = 32
然后我得到计数:
SELECT COUNT(*) FROM myTable WHERE requestFrom = $result AND adId = $adId AND requestStatus = '1'
-我只想在一个查询中执行此操作(获取计数)
+----+--------+-------------+------+--------+
| id | userId | requestFrom | adId | status |
+----+--------+-------------+------+--------+
| 1 | 23 | 58 | 32 | 1 |
| 2 | 23 | 65 | 37 | 0 |
| 3 | 76 | 27 | 73 | 1 |
| 4 | 29 | 58 | 29 | 1 |
1条答案
按热度按时间h43kikqp1#
使用子查询获取此