sql >> データベース >  >> RDS >> Sqlserver

個別のソフトウェア バージョンの個別のファイルの個別の値の合計を取得しようとしています

    これでうまくいくはずです:

    SELECT 
        Scenario_Name
        , Version
        , Measure
        , Value
     from
     (
        SELECT Scenario_Name, Measure, Version, SUM(Value) AS Value , 1 as ordering
        FROM #TableName
        GROUP BY Scenario_Name, Measure, version
        UNION ALL
        SELECT Scenario_Name, 'TotalPeople', Version, SUM(Value) , 2 as ordering
        FROM #TableName
        GROUP BY Scenario_Name, Version
    ) t
    Order by Scenario_Name, ordering, Measure
    

    編集:クエリに追加するには、次のようなことを試してください (クエリは ... の上に移動します):

    ...
    UNION ALL
    SELECT 
        (   SELECT attributedata 
            FROM [' [email protected]+ '].table1 
            WHERE AttributeName = ''Scenario Name''
        ) AS Scenario_Name
        , (
            SELECT attributedata 
            FROM [' [email protected]+ '].table1 
            where AttributeName = ''Version''
            ) AS Version
        , CAST(COUNT(*) AS float)/MAX(repnum) AS value
        , 'TotalPeople' AS Measure
        , GETDATE() AS DateRun
        , (SELECT ' + CAST(@testid as CHAR) +') AS TestNum 
    FROM [' [email protected]+ '].table2 
    

    EDIT2:同じことを達成しようとしている場合、解決策は本質的に同じだと思います:

        select (cast(count(id) as float)) as Value, FinalDisposition as Measure
        from TML_Casualties
        where FinalDisposition = 'DOW' or FinalDisposition = 'KIA'
        group by FinalDisposition
    UNION ALL
        select (cast(count(id) as float)) as Value, 'TotalDeaths' as Measure
        from TML_Casualties
        where FinalDisposition = 'DOW' or FinalDisposition = 'KIA'
    



    1. Oracle文字列の置換

    2. MySQL:ページとは何ですか?

    3. SearchOracle.comのADDM

    4. PHPMySQL-プリペアドステートメントにデフォルト値を挿入する方法