Hello i need help abou SQL a have this table
and i need this result.
thanks for your attention and your answers.
select to_char(r.date,'yyyy') YEAR, sum(1), sum(r.cafe) cafe, sum(r.drink) drink, sum(r.tea) tea from ucet a join drinks r on a.IDT=r.IDT join feat ce on a.IDT=ce.IDT join dance c on a.ID= c.ID group by to_char(r.date,'yyyy')
Advertisement
Answer
You can use a sum and group by as below:
SELECT DISTINCT YEAR(r.date) year, COUNT(DISTINCT(number)) number, SUM(r.cafe) cafe, SUM(r.drink) drink, SUM(r.tea) tea FROM drinks r JOIN ucet a on a.IDT = r.IDT GROUP BY YEAR(r.date)
Please also bear in mind that date is a reserved word for a datatype in many RDBMS systems, as such I would suggest naming your columns as something more appropriate, avoiding reserved words.