我的SQL查询似乎遇到了问题,这让我很生气.我似乎无法让小组上班.我一直收到以下错误:
00979. 00000 - "not a GROUP BY expression"
Run Code Online (Sandbox Code Playgroud)
我的查询:
SELECT customers.customer_first_name, customers.customer_last_name, orders.customer_numb, books.author_name, books.title
FROM customers
LEFT OUTER JOIN orders ON (orders.customer_numb = customers.customer_numb)
LEFT OUTER JOIN order_lines ON (order_lines.order_numb = orders.order_numb)
LEFT OUTER JOIN books ON (books.isbn = order_lines.isbn)
WHERE (customers.customer_numb = 6)
GROUP BY (books.title)
Run Code Online (Sandbox Code Playgroud)
数据库架构:
顾客:

订单行和订单:

我正在努力实现的目标: 我正在尝试按书名进行分组,以便它不显示重复的标题.
如果我错过了什么,我道歉,谢谢.
Gor*_*off 14
你不明白什么?您的select语句包含许多不在group by子句中的列.试试这个:
SELECT customers.customer_first_name, customers.customer_last_name, orders.customer_numb, books.author_name, books.title
FROM customers
LEFT OUTER JOIN orders ON (orders.customer_numb = customers.customer_numb)
LEFT OUTER JOIN order_lines ON (order_lines.order_numb = orders.order_numb)
LEFT OUTER JOIN books ON (books.isbn = order_lines.isbn)
WHERE (customers.customer_numb = 6)
GROUP BY customers.customer_first_name, customers.customer_last_name, orders.customer_numb, books.author_name, books.title
Run Code Online (Sandbox Code Playgroud)
既然你没有聚合任何东西,你可以免除group by,只需distinct在select条款中使用:
select distinct customers.customer_first_name, customers.customer_last_name, orders.customer_numb, books.author_name, books.title
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40112 次 |
| 最近记录: |