2

Let's say I have a PostgreSQL table with 10 columns and 2 weeks (w1 w2) with 5 countries. Something that would look like this :

Data

What I would like to do is a count per week and per column like this :

Result

0

2 Answers 2

6

As count() counts only the non-NULL values, this is a simple GROUP BY query:

SELECT week, count(col1), ..., count(col10)
  FROM your_table
 GROUP BY week;
0
0

You can get through below query:

SELECT  week, 
        SUM(Col1), SUM(Col2), SUM(Col3),  SUM(Col4),  SUM(Col5), 
        SUM(Col6), SUM(Col7), SUM(Col8),  SUM(Col9),  SUM(Col10) 
FROM <table name> 
GROUP BY 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.