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
Asked
Active
Viewed 1,480 times
-2
-
1Simply `select sum(col) from table where ...` – jarlh May 23 '16 at 13:53
-
2Can you post a sample of your data? – squillman May 23 '16 at 13:55
-
1Can you share your table's structure, some sample data, and the the result you're trying to get? It's a bit hard to follow the question as it's currently phrased. – Mureinik May 23 '16 at 13:56
-
2What DBMS are you using? Postgres, Sql Server, MySQL, Oracle? – JNevill May 23 '16 at 13:58
1 Answers
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