sql – 按两列分组,并在每行中显示总计
发布时间:2020-12-12 06:24:12 所属栏目:MsSql教程 来源:网络整理
导读:以下是列表数据. Code ItemCount Type Amount ----------------------------------------B001 1 Dell 10.00B001 1 Dell 10.00B001 1 Apple 10.00B001 2 Apple 20.00B001 2 Apple 20.00B114 1 Apple 30.50B114 1 Apple 10.00 我需要一个结果,按代码和类型进行
以下是列表数据.
Code ItemCount Type Amount ---------------------------------------- B001 1 Dell 10.00 B001 1 Dell 10.00 B001 1 Apple 10.00 B001 2 Apple 20.00 B001 2 Apple 20.00 B114 1 Apple 30.50 B114 1 Apple 10.00 我需要一个结果,按代码和类型进行分组,并且总计ItemCount,并获得每行中的Amount的总计. 这可能吗? Code ItemCount Type Amount ---------------------------------------- B001 2 Dell 110.50 B001 5 Apple 110.50 B114 2 Apple 110.50 解决方法请尝试:SELECT Code,SUM(ItemCount) ItemCount,Type,(SELECT SUM(Amount) FROM YourTable) Amount FROM YourTable GROUP BY Code,Type (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |