I have a table that holds the dates when a sponsor has sponsored the charity and another for the company. I would like to present the dates for the last 6 years on the same line but am struggling with the syntax. Could someone please point me in the right direction?
The syntax I have so far that for each year comes out on separate lines is:
select
SS_S_id,
S_Company_name,
(select '' from Sponsor_Sponsorship
B where A.SS_id=B.SS_id and substr(SS_Date,1,4)=substr(curdate(),1,4)-5) '2013',
(select '' from Sponsor_Sponsorship
B where A.SS_id=B.SS_id and substr(SS_Date,1,4)=substr(curdate(),1,4)-4) '2014',
(select '' from Sponsor_Sponsorship
B where A.SS_id=B.SS_id and substr(SS_Date,1,4)=substr(curdate(),1,4)-3) '2015',
(select '' from Sponsor_Sponsorship
B where A.SS_id=B.SS_id and substr(SS_Date,1,4)=substr(curdate(),1,4)-2) '2016',
(select '' from Sponsor_Sponsorship
B where A.SS_id=B.SS_id and substr(SS_Date,1,4)=substr(curdate(),1,4)-1) '2017',
(select '' from Sponsor_Sponsorship
B where A.SS_id=B.SS_id and substr(SS_Date,1,4)=substr(curdate(),1,4)) '2018'
from Sponsor_Sponsorship
A,
Sponsor
WHERE SS_S_id=S_id
AND SS_id>165
group by SS_id
This is the current results
SS_S_id S_Company_name 2013 2014 2015 2016 2017 2018
673 Whitecross Bakery NULL NULL NULL NULL NULL
675 Windsor Castle Bar and Restaurant NULL NULL NULL NULL NULL
676 Windwhistle Primary School NULL NULL NULL NULL NULL
677 Winnies Bakery NULL NULL NULL NULL NULL
678 Winstons Fish Bar NULL NULL NULL NULL NULL
679 Winterstoke Decorators Supply NULL NULL NULL NULL NULL
680 Worle Glass and Joinery NULL NULL NULL NULL NULL
681 WSM Counselling NULL NULL NULL NULL NULL
682 WSM Fasteners NULL NULL NULL NULL NULL **
682 WSM Fasteners NULL NULL NULL NULL NULL
682 WSM Fasteners NULL NULL NULL NULL NULL
But I would like it like this
SS_S_id S_Company_name 2013 2014 2015 2016 2017 2018
673 Whitecross Bakery NULL NULL NULL NULL ** NULL
675 Windsor Castle Bar and Restaurant NULL NULL NULL NULL NULL
676 Windwhistle Primary School NULL NULL NULL NULL NULL
677 Winnies Bakery NULL NULL NULL NULL NULL
678 Winstons Fish Bar NULL NULL NULL NULL NULL
679 Winterstoke Decorators Supply NULL NULL NULL NULL NULL
680 Worle Glass and Joinery NULL NULL NULL NULL NULL
681 WSM Counselling NULL NULL NULL NULL ** NULL
682 WSM Fasteners NULL NULL NULL **
It would also be good to get rid of the NULL's