Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

외래키로 연관이 있는 대략적인 부모상품(시단위) 정보와, 출발일,출발가격이 있는 실제 판매 상품정보가 있으며

부모상품기준으로 하위에 여러가지 여행상품이 존재한다.

고객의 사고는 이렇다. "3월에 3월또는 4월출발에 가장싼 서울 구경 여행상품을 구매하고 싶다."

실시간검색도 가능하지만 배치후 검색엔진에 태우기위한 용도....

sql버젼에따른 제약: http://d2.naver.com/helloworld/907716

...


...

제약조건: sql2008


Code Block
languagesql
themeEmacs
use study;

select * from tbl_basegoods;
select * from tbl_subgoods;

-- 기본+하위 상품 조인하여 모두 나타내기
select ts.id,(tb.gname+'-'+ts.gname) as goodsname ,ts.price,ts.startdate,ts.enddate from tbl_subgoods as ts
inner join tbl_basegoods tb on tb.id = ts.pid 
where ts.startdate   BETWEEN '2018-01-01' AND '2018-12-30';

-- 3월 4월 기본상품별 출발 최저가 : 편의를 위해 년도 생략 2018년이라고 가정....입력조건은 특정월....
with tmpView as(
	select DISTINCT MIN(ts.price)  OVER(PARTITION BY tb.id) as minprice,
	ts.id as sid,(tb.gname+'-'+ts.gname) as goodsname ,ts.price,ts.startdate,ts.enddate from tbl_subgoods as ts
	inner join tbl_basegoods tb on tb.id = ts.pid 
	where MONTH(ts.startdate) = 03
UNION ALL
	select DISTINCT MIN(ts.price)  OVER(PARTITION BY tb.id) as minprice,
	ts.id as sid,(tb.gname+'-'+ts.gname) as goodsname ,ts.price,ts.startdate,ts.enddate from tbl_subgoods as ts
	inner join tbl_basegoods tb on tb.id = ts.pid 
	where MONTH(ts.startdate) = 04
)
select tv.sid,tv.price,tv.goodsname, case when tv.minprice=tv.price then
CAST(MONTH(tv.startdate) AS VARCHAR(5)) +'월' else null end as bestmonth  from tmpView as tv where tv.minprice=tv.price

...