Mysql 如何消除sql中的相同日期值

Mysql 如何消除sql中的相同日期值,mysql,sql,Mysql,Sql,如果表中有以下数据 num | date_ | s | i_id -------+-------------+------------------------+--------- 1 | 2013-12-12 | (2,1,2013-12-12,80.56) | 2 1 | 2013-12-12 | (3,1,2013-12-12,70.56) | 3 1 | 2013-12-

如果表中有以下数据

 num   | date_       |           s            | i_id 
-------+-------------+------------------------+---------
     1 | 2013-12-12  | (2,1,2013-12-12,80.56) |       2
     1 | 2013-12-12  | (3,1,2013-12-12,70.56) |       3
     1 | 2013-12-10  | (4,1,2013-12-10,90.76) |       4
     2 | 2013-12-10  | (5,2,2013-12-10,90.76) |       5
     2 | 2013-12-06  | (6,2,2013-12-06,90.76) |       6
     3 | 2013-12-06  | (7,3,2013-12-06,90.76) |       7
     3 | 2013-12-06  | (8,3,2013-12-06,90.76) |       8
我想要一个查询,它将为同一个num具有不同日期的记录提供num,i\u id。 它应该返回num-1,2和相应的i_id。
如何继续?

这应该在版本号>=9.0的PostgreSQL中运行

select num, group_concat(i_id) as iids
from your_table
group by num
having count(distinct date_) > 1
SELECT
  num
, array_to_string(array_agg(i_id ORDER BY num), ',')
FROM a
GROUP BY num
见演示

在您的评论中,您希望获得最大值(日期)


参见演示

您能给出此示例的输出吗?你的问题不太清楚。@Mureinik:输出应该是num | date | s | i | id------------------------------------------------------------------------------------------------------------------------------------------------+-----------1 | 2013-12-12 |(2,12013-12-12-12,80.56)| 21 | 2013-12-10 |(4,12013-12-10,90.76)| 42 | 2013-12-10 |(5,22013-12-10,90.76)| 52 | 2013-12-06 |(6,22013-12-06,90.76)谢谢。如果在postgresql中执行相同的查询,组_concat()是否有效?还是应该使用数组来字符串?postgresql中没有
group\u concat
SELECT
  num
, MAX(date_)
, array_to_string(array_agg(i_id ORDER BY num), ',')
FROM a
GROUP BY num