group by说明解析
发布日期:2022-02-19 23:50:25
浏览次数:27
分类:技术文章
本文共 890 字,大约阅读时间需要 2 分钟。
Dept_id Clerk_name 1 a 1 b 2 c 3 d 要求:获取每个部门的员工总数 Select dept_id,count(*) as total From depertmant Where Group by dept_id Dept_id total [1] 部门表 员工表 Dept_id Clerk_id Clerk_id name 1 001 001 a 1 002 002 b 2 003 003 c 3 004 004 d 第一步完成后的结果: Dept_id Clerk_id Clerk_id name 1 001 001 a 1 001 002 b 1 001 003 c 1 001 004 d 1 002 …. …… 2 003 001 a … 3 004 001 a … 第二步完成之后的结果:(假设where department.clerk_id=employee.clerk_id) Dept_id Clerk_id Clerk_id name 1 001 001 a 1 002 002 b 2 003 003 c 3 004 004 d 第三步完成之后的结果:(group by depart_id) Dept_id Clerk_id Clerk_id name 1 001 001 a 1 002 002 b Dept_id Clerk_id Clerk_id name 2 003 003 c Dept_id Clerk_id Clerk_id name 3 004 004 d 第四步完成之后的结果: (假设select dept_id,count(*) as total from department,employee where department.clerk_id= employee.clerk_id) Dept_id total 1 2 Dept_id total 2 1 Dept_id total 3 1 第五步完成之后的结果(假设having count(*)>1) Dept_id total 1 2转载地址:https://blog.csdn.net/leslie_moon/article/details/83434033 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年03月22日 00时32分15秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【Leetcode刷题篇】leetcode108 将有序数组转换为二叉搜索树
2019-04-26
【Leetcode刷题篇】leetcoe109 有序链表转换二叉搜索树
2019-04-26
【Leetcode刷题篇】leetcode938 二叉搜索树的范围和
2019-04-26
【Leetcode刷题篇】leetcode235 二叉搜索树的最近公共祖先
2019-04-26
【Leetcode刷题篇】leetcode236 二叉树的最近公共祖先
2019-04-26
【Leetcode刷题篇】leetcode230 二叉搜索树中第K小的元素
2019-04-26
【Leetcode刷题篇】leetcode173 二叉搜索树迭代器
2019-04-26
【Leetcode刷题篇】leetcode99 恢复二叉搜索树
2019-04-26
【Leetcode刷题篇】leetcode451根据字符出现频率排序
2019-04-26
【Leetcode刷题篇】leetcode703 数据流中的第k大元素
2019-04-26
【Leetcode刷题篇】leetcode378 有序矩阵中第K小的元素
2019-04-26
【Leetcode刷题篇】前K个高频元素
2019-04-26
【Leetcode刷题篇】leetcode373 查找和最小的K对数字
2019-04-26
【Leetcode刷题篇】leetcode367 有效的完全平方数
2019-04-26
【Leetcode刷题篇】剑指offer-数值的整数次方
2019-04-26
【Leetcode刷题篇】面试题01.06 字符串压缩
2019-04-26
【Leetcode刷题篇】leetcode443 压缩字符串
2019-04-26
【面试篇】数据结构-线性表
2019-04-26
【面试篇】数据结构-树形结构
2019-04-26
【面试篇】数据结构-哈希表
2019-04-26