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 :: run sql command line download for windows 10 
Sql :: how to change a column name in postgresql 
Sql :: oracle nextval insert 
Sql :: drop table if exists test 
Sql :: ms sql create user 
Sql :: current date sql 
Sql :: get all columns from table sql 
Sql :: create sequence postgres 
Sql :: sql round down to nearest integer 
Sql :: if else in postgresql 
Sql :: sql count 
Sql :: sql first 
Sql :: sqlite indexes 
Sql :: select last 30 days sql 
Sql :: sql convert date to string yyyy-mm-dd 
Sql :: modify column name in sql 
Sql :: postgre describe table 
Sql :: phone no data type in sql server 
Sql :: remove space in sql server 2012 
Sql :: myswql show full processlist 
Sql :: sql server datetime to string 
Sql :: mysql check if lowercase 
Sql :: sql convert datetime to year 
Sql :: change mariadb to mysql xampp 
Sql :: postgresql import a database of gzip 
Sql :: how to get 30 days previous date in mysql 
Sql :: for json path sql server 
Sql :: copy data from one table to another mysql 
Sql :: sql server create constraint 
Sql :: how to select an index in oracle sql 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =