Search
 
SCRIPT & CODE EXAMPLE
 

SQL

case when with count and combining similar values in sql

SELECT 
    data.id,
    data.lastname,
    data.firstname,
    SUM(data.WebData) AS WebData,
    SUM(data.InternalData) AS InternalData,
    SUM(data.countid) AS Countid
FROM
    (
       SELECT id,lastname,
              firstname,datasource,
              CASE WHEN Datasource = 'Web' THEN Count(Datasource) ELSE 0 END WebData,
              CASE WHEN Datasource = 'Internal' THEN Count(Datasource)ELSE 0 END InternalData,
             count(id) AS Countid

        FROM Table
        GROUP BY
                 id,lastname,firstname,datasource
     ) AS data
GROUP BY 
    data.id,data.firstname,data.lastname
Comment

PREVIOUS NEXT
Code Example
Sql :: mariadb set vertical output format 
Sql :: sql promises req, res 
Sql :: do you know sql 
Sql :: how to ignore the data based on specific keywords? 
Sql :: Sql testing queries 
Sql :: how to create roles in oracle developer sql 
Sql :: mysql beautify output 
Sql :: strftime format sqlite 
Sql :: How to get distinct sets of rows using SQL (Oracle)? 
Sql :: postrgres trunc 
Sql :: Run batch file from SQL 
Sql :: error database connection 
Sql :: distinct 
Sql :: print orcale 
Sql :: how to reset mysql table auto_increment 
Sql :: connecting to my cloud sql server with c# 
Sql :: compare strings lexicographically in sql 
Sql :: postgresql display subquery as json 
Sql :: ORA-01400 
Sql :: sql date range 
Sql :: loop through a table variable in TSQL without using a cursor 
Sql :: sql select students closest in score 
Sql :: SQL single column 
Sql :: SQL-Arten 
Sql :: connecting mySQL to STS 
Sql :: format datetime mysql 
Sql :: sql queries questions 
Sql :: oracle foreign key reference table 
Sql :: psotgres multiple values 
Sql :: add 10 to all numbers in a column sql 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =