📜  在 sql 代码示例中使用 count 并组合相似值的情况

📅  最后修改于: 2022-03-11 15:04:58.840000             🧑  作者: Mango

代码示例1
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