i have a event table,
| id | title | date |
| 1 | party | 2011-02-02 |
| 2 | party | 2011-02-03 |
| 3 | party | 2011-02-04 |
| 4 | party | 2011-02-05 |
| 5 | brunch | 2011-05-20 |
| 6 | brunch | 2011-05-21 |
| 7 | brunch | 2011-05-22 |
| 8 | brunch | 2011-05-23 |
i want to transfer data this structure
| id | title | start | finish |
| 1 | party | 2011-02-02 | 2011-02-05 |
| 2 | brunch | 2011-05-20 | 2011-05-23 |
what is best way ?
Without the new ID:
SELECT title, MIN(date) AS start, MAX(date) AS finish
FROM event
GROUP BY title
To generate a new ID use a counter:
SET @counter = 0;
SELECT ((@counter := (@counter+1))) AS id, title, MIN(date) AS start, MAX(date) AS finish
FROM event
GROUP BY title
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With