0

I have a set of MySQL data similar to the following:

| id | type       | start               | end                 |
===============================================================
|  1 |      event | 2011-11-01T00:00:00 | 2012-01-02T00:00:00 |
|  2 |    showing | 2012-11-04T00:00:00 | 2012-11-04T00:00:00 |
|  3 | conference | 2012-12-01T00:00:00 | 2012-12-04T00:00:00 |
|  4 |     event2 | 2012-01-01T00:00:00 | 2012-01-01T00:00:00 |

I want to retrieve events within a certain date range, but I also want to return individual results for each row that has a time span of more than one day. What's the best way to achieve this?

EDIT: In other words, I want to return two results from the event row, four results from the conference row and a single result for all the others.

Any ideas would be greatly appreciated.

4

1 回答 1

1

试试这个说法:

SELECT * FROM table
WHERE START BETWEEN '2012-01-01' AND '2012-01-03'
OR END BETWEEN '2012-01-01' AND '2012-01-03'    
OR TO_DAYS(end) - TO_DAYS(start) > 1

我创建它是为了在SQL Fiddle上进行测试

于 2012-10-30T10:13:29.467 回答