아래와 같은 쿼리를 날리면
select
input, stair, app_id, level
from
tb_stat_batt_real
where
(input >= convert(char(6), getdate(), 12)) and
(input < convert(char(6), getdate()+1, 12))
다음과 같은 결과가 나오는데
input stair app_id level
2009-08-27 13:17:03.830 2 161 34
2009-08-27 13:17:03.830 2 162 34
2009-08-27 13:17:03.830 2 163 34
2009-08-27 13:17:04.840 2 124 24
2009-08-27 13:17:05.840 2 190 62
2009-08-27 13:17:05.840 2 191 62
2009-08-27 13:17:05.843 2 192 62
2009-08-27 13:17:05.843 2 193 62
2009-08-27 13:17:05.843 2 194 62
2009-08-27 13:17:05.843 2 195 62
2009-08-27 13:17:06.840 1 296 45
2009-08-27 13:17:07.833 2 217 61
2009-08-27 13:17:07.833 2 218 61
2009-08-27 13:17:07.833 2 219 61
2009-08-27 13:17:08.840 2 243 42
2009-08-27 13:17:08.840 2 244 42
2009-08-27 13:17:08.840 2 245 42
2009-08-27 13:17:09.837 2 163 91
2009-08-27 13:17:09.837 2 164 91
2009-08-27 13:17:09.837 2 165 91
2009-08-27 13:17:09.837 2 166 91
2009-08-27 13:17:10.840 -1 372 53
2009-08-27 13:17:10.840 -1 373 53
2009-08-27 13:17:10.840 -1 374 53
2009-08-27 13:17:10.840 -1 375 53
2009-08-27 13:17:10.840 -1 376 53
2009-08-27 13:17:10.840 -1 377 53
2009-08-27 13:17:11.830 -1 412 21
2009-08-27 13:17:11.850 -1 413 21
2009-08-27 13:17:11.850 -1 414 21
2009-08-27 13:17:11.860 -1 415 21
.....................................................................
.....................................................................
.....................................................................
.....................................................................
.....................................................................
여기서 문제는 오늘 날짜 중 가장 최근에 발생된 'level' 필드 값을
얻어오는 방법을 알고 싶습니다.
단, 'stair'와 'app_id'는 중복 없이 나와야 됩니다.
즉, 'stair'와 'app_id'가 동일한 값으로 중복하여 출력되어서는 안됩니다.
답변 바랍니다. |