Search
 
SCRIPT & CODE EXAMPLE
 

SQL

multiple count in sql

SELECT distributor_id,
    count(*) AS Total,
    sum(CASE WHEN inflevel = 'exec' THEN 1 ELSE 0 END) AS ExecCount,
    sum(CASE WHEN inflevel = 'personal' THEN 1 ELSE 0 END) AS PersonalCount
FROM yourtable
GROUP BY distributor_id
Comment

multiple count with where clause sql

SELECT distributor_id,
    count(*) AS total,
    sum(case when level = 'exec' then 1 else 0 end) AS ExecCount,
    sum(case when level = 'personal' then 1 else 0 end) AS PersonalCount
FROM yourtable
GROUP BY distributor_id
Comment

PREVIOUS NEXT
Code Example
Sql :: Upgrading postgresql data from 13 to 14 failed! 
Sql :: sql alchemy or 
Sql :: sql select inside select 
Sql :: psql select * from table 
Sql :: oracle right characters 
Sql :: import data from csv to sql server 
Sql :: mac django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? 
Sql :: tablas bootstrap responsive sql server para datos vivos 
Sql :: ignore case in string sql 
Sql :: select database in mysql 
Sql :: pl sql create table from another table 
Sql :: mysql timezone 
Sql :: sqlite select split string 
Sql :: sql stored procedure with table parameter 
Sql :: select value from previous row in postgresql 
Sql :: create foreign key postgres 
Sql :: unique in sql server 
Sql :: sql duplicate a table with data 
Sql :: oracle gather table statistics 
Sql :: postgres having 
Sql :: postegresql update to null 
Sql :: how to find top 3 salary in sql 
Sql :: r write csv without index 
Sql :: mysql server not running 
Sql :: cast in sql 
Sql :: insert to postgres table 
Sql :: having in sql server 
Sql :: ORACLE sql join multiple tables 
Sql :: delete table sqlite 
Sql :: dump sql file to database postgres 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =