数据库行合并

month  callnum

1   12221
 2   3232323
 3   12224
 1   12224
 1   12223
 2   22233
 2   12221
3    5555
3    58877
3    5555
1    12221
2    12224
3    12221
2    22233

把相同的月份的不同行合并 结果是
month     callnum
1     12221/12221/12223/12224
2     3232323/22233/12224/12221/22233
3     12224/12221/5555/58877/5555
SQL语句如下:
 SELECT MONTH, REPLACE(WMSYS.WM_CONCAT(CALLNUM), ',' , '/') AS "NEW_NUM"
  FROM DETAIL T GROUP BY MONTH;

选出每个月都来电的号码并计算每个月该号码的来电次数

select t.callnum, count( distinct t.month) from DETAIL t  group by callnum
having  count (distinct t.month) =(select(count (distinct t.month)) from  DETAIL t)

05-17 05:22