-2

I just have to omit those records whose sum of sales in all 53 weeks is 0 and would need the output without group by

shyam iyer
  • 57
  • 1
  • 7

1 Answers1

0

You cannnot really get that in one query. To get all years without any sum of sales, you have to sum the sales.

That is: Firstly: select YEAR(date) from YourTable group by YEAR(date) having sum(sales) > 0

Then: select * from YourTable where Year in (<firstquery>) as aliasname order by <anydatecolumn>

If you are using mssql you can do that in one query using the OVER clause and partitioning

swe
  • 1,416
  • 16
  • 26