sql - SQL - 按一列计数和排序
问题描述
需要帮助来计算 Access 中的表并按该特定类型对它们进行分组。
例如,我有这张桌子
我需要它在查询中输出到这个:
解决方案
这是条件聚合的一个例子。在 MS Access 中,语法为:
select itemname, itemtype,
sum(iif(building = 'A', 1, 0)) as totalA,
sum(iif(building = 'B', 1, 0)) as totalB,
sum(iif(building = 'C', 1, 0)) as totalC
from t
group by itemname, itemtype
order by itemname, itemtype;
推荐阅读
- android - 颤振 upi 交易不工作(错误)
- mysql - 如何在 AWS Linux 1 中安装 MySql 8?
- python - 在规范化期间屏蔽 0 值
- ios - NavigationView 中意外填充 Swift UI 列表
- swift - 在 ios 应用程序中打开任何电子邮件附件
- amazon-web-services - AWS Amplify ci/cd 在测试阶段挂起
- python - 如何将熊猫系列的列值转换为Python中的列表?
- conditional-statements - 如何在火花流中删除其他结果?
- laravel - Laravel:调用自定义外观的问题
- java - 如何获取 TypeLiteral 绑定或可以说来自注入器的实例 [Google Guice]