提交 a9d61d98 编写于 作者: M Mars Liu

in cloumn subquery

上级 1539015a
{
"node_id": "mysql-06525286a9d4488d94e85b6bd36e3c1e",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [
["mysql", "not in"]
],
"keywords_forbid": [],
"group": 0
}
\ No newline at end of file
{
"node_id": "mysql-7bc092b1b1854dd3b88eed3a517b96a2",
"keywords": ["子查询", "列子查询"],
"keywords": [
"子查询",
"列子查询"
],
"children": [],
"export": [],
"export": [
"in_column.json"
],
"keywords_must": [
["mysql", "列子查询"]
[
"mysql",
"列子查询"
]
],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "ccat",
"source": "in_column.md",
"notebook_enable": false,
"exercise_id": "2ded48602e384fc2b5476186e8b91842"
}
\ No newline at end of file
{
"type": "code_options",
"author": null,
"source": "in_column.md",
"notebook_enable": false,
"exercise_id": "464fd8f686284280afbee9424ed4ae65"
}
\ No newline at end of file
# 列子查询
Joe 打算写一个查询,根据员工表
```mysql
create table employee(
id int primary key auto_increment,
dept varchar(256),
name varchar(256),
post varchar(16)
)
```
统计每个部门的人数,但是他不打算用 group by。那么还可以怎做?
## 答案
```mysql
select distinct(dept) as dept,
(select count(*) from employee as i where i.dept=o.dept) as emp
from employee as o
```
\ No newline at end of file
......@@ -1240,21 +1240,6 @@
"group": 0
}
},
{
" NOT IN": {
"node_id": "mysql-06525286a9d4488d94e85b6bd36e3c1e",
"keywords": [],
"children": [],
"keywords_must": [
[
"mysql",
"not in"
]
],
"keywords_forbid": [],
"group": 0
}
},
{
" 列子查询": {
"node_id": "mysql-7bc092b1b1854dd3b88eed3a517b96a2",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册