mysql - SQL 仅选择一项

标签 mysql sql google-bigquery

假设我有一张像这样的 table :

ID        Description
1        A popular place to eat!
1        A popular place to eat!!
1        A popular place to eat!!!
2        Lets go!
2        Everyone, Lets go!

我只想要每个 ID 的描述之一,因为它们在不相关的方面有所不同:

ID        Description
1        A popular place to eat!
2        Everyone, Lets go!

如何编写 SQL 查询从表 1 生成表 2?

最佳答案

按您希望唯一的列进行分组,并在 description 列上使用任何聚合函数,例如 min()max()

select id, min(description)
from your_table
group by id

关于mysql - SQL 仅选择一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46203025/

相关文章:

sql - Postgres - 具有 WHERE AND 条件的单列上的多个条件?

youtube - 在BigQuery中获取视频标题

google-bigquery - 从地理点 BigQuery 创建多边形

java - 从存储过程返回空值

python - 导入 MySQLdb ImportError

php - Cakephp 2.x 中的 Ajax

sql - PIVOT SQL Server 协助

mysql - 仅当另一个外键匹配时才允许外键插入

python - cx_Oracle 忽略 order by 子句

c# - 拒绝 BigQuery 中的结果