我正在尝试从两个表中进行复杂的查询...这是技能测验中的一个问题。
桌子
**Orders Customer**s
id id
date first_name
shipping_amount last_name
order_status city
customer_id (Customers.id) state
输出
-----------+------------+
| State | # Orders |
+-----------+------------+
| NY | 55 |
| CA | 40 |
| NJ | 33 |
| FL | 21 |
| MO | 12 |
+-----------+------------+
我一直在处理我的查询,它看起来像这样......
select DISTINCT state, (select count(id) Orders
from customers
group by state
ORDER BY Orders DESC) FROM Customers
它给了我一个错误,说子查询返回超过 1 行