简体   繁体   中英

Mysql select multiple rows based on one row related date range

SQL structure

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

I need sql statment to receive duplicate rows from startdate to enddate range.

Example result would be:

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

Does anyone have an idea how to solve this???

It should be something like this :

SELECT
  id, startdate, enddate
FROM
  myTable
WHERE
  (startdate, enddate) IN 
  (
    SELECT
      startdate, enddate
    FROM
       myTable
    GROUP BY
      startdate, enddate
    HAVING
      COUNT(*) > 1     
  )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM