Created
          January 28, 2022 22:59 
        
      - 
      
- 
        Save farukcan/0daf701554bfc3e50b9b7e62c1560db1 to your computer and use it in GitHub Desktop. 
    Daily, Weekly, Total Row Count in Multiple Columns
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | SELECT | |
| SUM(CASE WHEN KY='daily' THEN COUNT ELSE 0 END) "daily", | |
| SUM(CASE WHEN KY='weekly' THEN count ELSE 0 END) "weekly", | |
| SUM(CASE WHEN KY='total' THEN count ELSE 0 END) "total" | |
| FROM | |
| ( | |
| SELECT 'daily' AS KY ,COUNT(*) FROM PUBLIC."Articles" WHERE "Articles"."createdAt" >= NOW() - '1 day'::INTERVAL | |
| UNION | |
| SELECT 'weekly' AS KY ,COUNT(*) FROM PUBLIC."Articles" WHERE "Articles"."createdAt" >= NOW() - '1 week'::INTERVAL | |
| UNION | |
| SELECT 'total' AS KY ,COUNT(*) FROM PUBLIC."Articles" | |
| ) AS TB | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Note: It's for postgresql