SQL查询不会按时间和日期排序

时间:2014-04-30 16:51:47

标签: sql sql-server sqlsrv

我正在处理我的sql查询,我按时间和日期排序,但不确定为什么它的订购不正确。它在30日之前显示日期29:

SELECT measurements.title as Tittel, routines.value as Verdi, CONVERT(VARCHAR(10),routines.date,103) as Dato, convert(VARCHAR(10), routines.time, 108) as Tid, pools.name as Basseng, emps.user_name as Ansatt
FROM routines, measure_routine, measurements, pools, emps
WHERE routines.id = measure_routine.routine_id
AND measure_routine.measure_id = measurements.id
AND (measurements.title  Like 'T_%') AND measure_routine.pool_id=pools.id AND routines.emp_id=emps.id 
AND Date between '2014-04-29' and '2014-04-30'
order BY routines.date, routines.time

1 个答案:

答案 0 :(得分:3)

那是因为它按升序排序。如果你想要30后30,那么你需要下降。

SELECT measurements.title as Tittel, routines.value as Verdi, CONVERT(VARCHAR(10),routines.date,103) as Dato, convert(VARCHAR(10), routines.time, 108) as Tid, pools.name as Basseng, emps.user_name as Ansatt
FROM routines, measure_routine, measurements, pools, emps
WHERE routines.id = measure_routine.routine_id
AND measure_routine.measure_id = measurements.id
AND (measurements.title  Like 'T_%') AND measure_routine.pool_id=pools.id AND routines.emp_id=emps.id 
AND Date between '2014-04-29' and '2014-04-30'
order BY routines.date desc, routines.time desc