我们可以对 group_concat(distinct somefield) 进行 DISTINCT 吗?

Can we make a DISTINCT of a group_concat(distinct somefield)?(我们可以对 group_concat(distinct somefield) 进行 DISTINCT 吗?)
本文介绍了我们可以对 group_concat(distinct somefield) 进行 DISTINCT 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://sqlfiddle.com/#!2/37dd94/17

如果我执行 SELECT DISTINCT,我会得到与仅执行 SELECT 相同的结果.

If I do SELECT DISTINCT I get the same results as doing just SELECT.

在查询结果中,您将看到两个包含Evora"区的活动.只有一个应该出现.

On the query results, you will see two activities that contains the District "Evora". Only one should appear.

有什么线索吗?

推荐答案

下面的查询怎么样 (SQL FIDDLE):

How about the following query (SQL FIDDLE):

SELECT GROUP_CONCAT(APA_T.district), t.name
FROM tbl_activity AS t 
JOIN tbl_activity_package AS ap ON t.id = ap.id_activity 
JOIN 
(
  SELECT DISTINCT apa.district AS district, 
  (
     SELECT s1.id_activity_package 
     FROM tbl_activity_package_address s1
     WHERE apa.district = s1.district
     ORDER BY s1.id DESC
     LIMIT 1
  ) AS idActivityPackage
  FROM 
  tbl_activity_package_address apa
  ORDER BY apa.district
) AS APA_T
ON ap.id = APA_T.idActivityPackage
GROUP BY t.name 
ORDER BY APA_T.district;

上面的查询会去掉多余的FaroEvora.

The above query will eliminate the extra Faro and Evora.

这篇关于我们可以对 group_concat(distinct somefield) 进行 DISTINCT 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)