블로그 이미지
010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (500)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total
Today
Yesterday

달력

« » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

공지사항

최근에 올라온 글

if object_id ('temp') is not null
drop table temp 
go

create table temp
(id varchar(20)
, time time 
, product varchar(100)
) 
go

insert into temp (id, time, product)
select id, time, product 
from 
	( 
	  values 
	  ('A', '08:10', 'pizza' )
	, ('A', '09:55', 'noodle' )
	, ('B', '12:30', 'pizza' )
	) a (id, time, product)
go

-- Consider the pros and cons of both queries.
-- 1 
; with a
as 
(
select row_number() over (partition by id order by time asc) rn , * 
from temp 
)
select *
from a 
where rn = 1 

-- 2
select b.*
from 
	(
	select distinct id 
	from temp a
	) a
	cross apply 
	(
	select top 1 * 
	from temp 
	where id = a.id
	order by time 
	) b
Posted by 보미아빠
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함