문제

I want to select value from database that start with a dynamic input like this

SELECT * FROM employee  OFFSET JoinDate = '$input' LIMIT 7

I'd like to select all the field in employee table where JoinDate start from the input, let say from '25-03-2014' until 7 days later. But the offset is wrong. Could anyone help me?

도움이 되었습니까?

해결책

This:

SELECT *
  FROM employee
 WHERE JoinDate >= '$input'
   AND JoinDate <= '$input' + INTERVAL 7 DAY

or use BETWEEN

다른 팁

Is the table ordered by date? If you want to select the 7 records right after the search hit - I think you could do something like:

SELECT * FROM employee WHERE JoinDate >= '$input' LIMIT 7 ORDER BY JoinDate ASC;

If you want to select all dates within a range, you could:

SELECT * FROM employee WHERE JoinDate >= '$input' AND JoinDate <= '$input' + INTERVAL 7 DAY ORDER BY JoinDate ASC;

Use Interval:

SELECT * FROM employee WHERE JoinDate >= '$input' AND JoinDate <= '$input' + INTERVAL 7 DAY

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top