【发布时间】:2022-01-01 03:44:28
【问题描述】:
我正在自学Psql函数,我只想返回一行一列名:dep_people,不知道如何解决这一问题的一行一列名。请帮我理解Psql函数。
预览表格
SELECT * FROM test_sch.apollo_org_job_function;
|-------------------------------------------|
|organization_id |department |no_people|
|-------------------------------------------|
| 2a |accounting | 3 |
| 1a |engineering | 2 |
| 1a |entrepreneurship| 1 |
| 1a |human resources | 4 |
|-------------------------------------------|
我在这里
SELECT
department, no_people
FROM test_sch.apollo_org_job_function
GROUP BY department, no_people
ORDER BY department;
我的回报是:
|--------------------------|
|department |no_people|
|--------------------------|
|accounting | 3 |
|engineering | 2 |
|entrepreneurship| 1 |
|human resources | 4 |
|--------------------------|
调用函数
select * from test_sch.return_dep_people('1a')
as f(dep_people text);
预期输出
------------------------------------------------------|
|dep_people |
------------------------------------------------------|
|Engineering:2 , human_resources:4, entrepreneurship:1|
-------------------------------------------------------
注意:结果应仅包含名为“dep_people”的 1 列和字符串中的 1 行,(“Engineering:2 , human_resources:4, corporate:1”是单个字符串)
【问题讨论】:
-
我错过了排除
'accounting'的规则...
标签: sql postgresql aggregate-functions