Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sandrapoh
Starting Member
1 Post |
Posted - 2015-04-09 : 01:51:43
|
Dear All,Good day... I have came out with 2 SQL statement as shown below.STATEMENT ONE=============select B.cal_year, SUM(days_to_cancel) from fact_bookings Ajoin dim_date as B on B.dim_date_key=A.dim_booking_date_singapore_keygroup by B.cal_yearorder by B.cal_yearOUTPUT ONE==========cal_year SUM(days_to_cancel)2013 101387232014 10333452STATEMENT TWO=============select B.cal_year, SUM(day_target) from booking_targets_daily Ajoin dim_date as B on B.dim_date_key=A.dim_date_keygroup by B.cal_yearorder by B.cal_yearOUTPUT TWO==========cal_year SUM(Booking_Targets)2010 522728272011 625567782012 621664802013 757034622014 812486992015 87440948.35I need a Statement that combined the above 2 statement which output to be like the below. How to?cal_year SUM(days_to_cancel) Sum(Booking_Targets)2013 10138723 757034622014 10333452 81248699Many Thanks&Best RegardsSandra Poh |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2015-04-09 : 06:40:45
|
will you get only single record always for each year in both the outputs?Javeed Ahmedhttps://www.linkedin.com/pub/javeed-ahmed/25/5b/95 |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2015-04-09 : 06:46:39
|
can you try thisselect B.cal_year, SUM(days_to_cancel) as days_to_cancel into #temp1 from fact_bookings Ajoin dim_date as B on B.dim_date_key=A.dim_booking_date_singapore_keygroup by B.cal_yearorder by B.cal_yearselect B.cal_year, SUM(day_target) as day_target into #temp2from booking_targets_daily Ajoin dim_date as B on B.dim_date_key=A.dim_date_keygroup by B.cal_yearorder by B.cal_yearselect a.cal_year,a.days_to_cancel,b.day_target from #temp1 ainner join #temp2 bon a.cal_year=b.cal_yeardrop #temp1drop #temp2Javeed Ahmedhttps://www.linkedin.com/pub/javeed-ahmed/25/5b/95 |
|
|
|
|
|