SQL Server查询所需的结果 [英] SQL Server query for the required result

查看:94
本文介绍了SQL Server查询所需的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





Hi,

ID | Name |Dept |Gender
=======================
1  |ABC   |DPT1 |M
2  |DEF   |DPT2 |M
3  |GHI   |DPT1 |F
4  |JKL   |DPT2 |F
5  |MNO   |DPT3 |M
6  |PQR   |DPT1 |M





以上是我想要下面结果的表格。





Above is the table from which I want the below result.

Dept |Gender|Count
==================
DPT1 |M     |2
DPT2 |M     |1
DPT3 |M     |1
DPT1 |F     |1
DPT2 |F     |1
DPT3 |F     |0





什么是查询SQL Server。?



谢谢,

Janes T



What is the query in SQL Server.?

Thanks,
Janes T

推荐答案

选择dept,gender,count(name)来自myTable group by dept,gender



您应该阅读我关于SQL的文章,因为这是一个非常基本的请求,我在选择的文章中介绍它。





这里 [ ^ ]
Select dept, gender, count(name) from myTable group by dept, gender

You should read my articles on SQL, because this is quite a basic request, and I cover it in my article on 'select'.


Here[^]


这篇关于SQL Server查询所需的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆