sql case and condition code example
Example 1: sql CASE
/*CASE statements are used to create different outputs and is
used by SQL as a way to handle if-then logic.*/
SELECT column_name,
CASE
WHEN condition THEN
WHEN condition THEN
ELSE
END
FROM table_name;
Example 2: 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 =
CASE WHEN Datasource =
count(id) AS Countid
FROM Table
GROUP BY
id,lastname,firstname,datasource
) AS data
GROUP BY
data.id,data.firstname,data.lastname