1

SQL结构

id, startdate, enddate  
1, 2012-01-01, 2012-10-01  

我需要 sql 语句来接收从 startdate 到 enddate 范围的重复行。

示例结果将是:

1, 2012-01-01
1, 2012-02-01
1, 2012-03-01
...
1, 2012-10-01  

有谁知道如何解决这个问题???

4

1 回答 1

0

它应该是这样的:

SELECT
  id, startdate, enddate
FROM
  myTable
WHERE
  (startdate, enddate) IN 
  (
    SELECT
      startdate, enddate
    FROM
       myTable
    GROUP BY
      startdate, enddate
    HAVING
      COUNT(*) > 1     
  )
于 2012-07-20T11:59:49.847 回答