I'm trying to apply DISTINCT
on only one column.
我正在尝试仅在一列上应用DISTINCT。
The question is:
问题是:
Who is ordering equipment where the description begins with "tennis" or "volleyball".
谁在订购设备,描述以“网球”或“排球”开头。
Include:
包括:
- Customer number,
- 顾客号码,
- Stock number, and
- 股票编号,和
- Description
- 描述
Do not repeat any rows.
不要重复任何行。
This is what the tables look like: Items
, Stock
, Orders
这就是表格的样子:商品,库存,订单
This is my code:
这是我的代码:
select distinct
orders.customer_num, stock.stock_num, stock.description
from
orders
join
items on items.order_num = orders.order_num
join
stock on stock.stock_num = items.stock_num
where
stock.description like 'tennis%'
or stock.description like 'volleyball%';
The result is:
结果是:
But I'm trying to get no repeating numbers on the CUSTOMER_NUM
column.
但我试图在CUSTOMER_NUM列上没有重复的数字。
Thank you..
谢谢..
2 个解决方案
#1
0
There is a possibility that your join condition is wrong.please try joining item table to customer table with condition as items.customer_num =customer.customer_num .I am not sure whether it will work as we dont have correct data of these tables.
您的连接条件有可能是错误的。请尝试将条目表连接到客户表,条件为items.customer_num = customer.customer_num。我不确定它是否会起作用,因为我们没有这些表的正确数据。
#2
0
I'm not sure you'll see this, but I don't believe the rows aren't repeating. Look at the description. You're only getting one different item description per customer number which don't repeat for that customer number. You can see this by adding in: 'order by orders.customer_num, stock.stock_num;' to the end.
我不确定你会看到这个,但我不相信这些行不会重复。看看描述。您只能为每个客户编号获取一个不同的项目描述,而不会重复该客户编号。你可以通过添加:'order by orders.customer_num,stock.stock_num;'来看到这一点。到最后。
#1
0
There is a possibility that your join condition is wrong.please try joining item table to customer table with condition as items.customer_num =customer.customer_num .I am not sure whether it will work as we dont have correct data of these tables.
您的连接条件有可能是错误的。请尝试将条目表连接到客户表,条件为items.customer_num = customer.customer_num。我不确定它是否会起作用,因为我们没有这些表的正确数据。
#2
0
I'm not sure you'll see this, but I don't believe the rows aren't repeating. Look at the description. You're only getting one different item description per customer number which don't repeat for that customer number. You can see this by adding in: 'order by orders.customer_num, stock.stock_num;' to the end.
我不确定你会看到这个,但我不相信这些行不会重复。看看描述。您只能为每个客户编号获取一个不同的项目描述,而不会重复该客户编号。你可以通过添加:'order by orders.customer_num,stock.stock_num;'来看到这一点。到最后。