我试图按日期实施简单的区域预订申请
我记录了预订请求
总面积是常数:假设100sqft
表:
req_made
STARTDATE |结束日期|面积| storagename
示例:
01 Aug|__________________________________100_avail________________________|31 Aug
06 Aug|____________________________50_____________|25 Aug
05 Aug|____40__________|11 Aug
18 Aug|____30_______|23 Aug
13 Aug|_10_|16 Aug
My Request: 08 Aug|#######################|20 Aug
Answer=>Maximum possible within range 10
Area Free:
|-------100---||---10----------|-|-40-|50|-------20----|-50|--100--|
60 50
Same Diagram in written format (Picture)
我的SQL查询尝试:
SELECT (100-SUM(req_made.area)) AS area,req_made.storagename
FROM req_made
WHERE (req_made.enddate >= '2016-08-20' AND
req_made.startdate <= '2016-08-20')
OR(req_made.enddate>='2016-08-08' AND
req_made.startdate<= '2016-08-08')
OR(req_made.enddate<='2016-08-20' AND
req_made.startdate>= '2016-08-08')
GROUP BY req_made.storagename
结果 -30 | my_storage
预期 10 | my_storage