mysql - 如何在 SQL 中的一列上选择不重复的记录?
问题描述
我有一个包含 3 列的表格,如下所示:
+------------+---------------+-------+
| Industry | country | price |
+------------+---------------+-------+
Retail |UK | 20
Retail | Japan | 30
Retail | Germany | 40
Retail | America | 50
我想要的结果是这样的:
+------------+---------------+-------+
| Industry | country | price |
+------------+---------------+-------+
Retail | UK | 20
| Japan | 40
| Germany | 40
| America | 50
我需要没有任何重复的行业类别。最好的 SQL 命令是什么?
解决方案
如果适合您,您可以尝试以下方法。我也添加了 SQL 小提琴链接
http://sqlfiddle.com/#!4/d162a4/10
select (case when row_id=1 then industry else ' ' end) industry
,country
,price
from (select industry,country
,price
,row_number() over(partition by industry order by rownum) row_id
from prices
) tmp
推荐阅读
- flutter - 抽屉到 EndDrawer 颤动
- opencv - 如何使用 OpenCV 使用 Tesseract 自动处理 OCR 的图像
- excel - VBA 中的 UTF-8 字符 Shell_NotifyIconW
- python - Django INNER JOIN 和 WHERE
- wordpress - 通过 AWS 将网站复制到 WP Bitnami Multi Server
- average - 如何像 B(2+4) 一样在 libreoffice calc 中表示单元格?
- arrays - 这个数组声明在 C 语言中有效吗?
- vba - 导航选项卡:如何停止从一个选项卡移动到另一个选项卡
- ios - 如何使 iOS 应用程序识别为 AudioUnit?
- python - 将年份字符串(例如“2021”)转换为熊猫分析中的分类