在MySQL中,使用DISTINCT关键字可以过滤掉重复的数据。下面是一个示例,演示如何在部分列结果上使用DISTINCT:
假设我们有一个名为"customers"的表,其中包含"customer_id"、"customer_name"和"customer_city"三个列。
要在"customer_city"列上使用DISTINCT,可以使用以下查询语句:
SELECT DISTINCT customer_city FROM customers;
这将返回不重复的"customer_city"值的列表。
如果想要在多个列上使用DISTINCT,可以使用以下查询语句:
SELECT DISTINCT customer_name, customer_city FROM customers;
这将返回不重复的"customer_name"和"customer_city"值的组合。
希望以上示例能够解决你的问题。
下一篇:部分列匹配的rbind?