表emp中有2列作业和部门。
job department ------------------------------------------- manager accounting president accounting manager accounting clerk accounting manager accounting manager accounting manager accounting clerk accounting analyst accounting security accounting security accounting clerk accounting analyst accounting security accounting
我需要提取如下数据
status status_numbers status status_numbers ------------------------------------------------------------------------------ Total 14 Total 14 manager 5 manager 5 president 1 president 1 clerk 3 clerk 3 analyst 2 analyst 2 security 3 security 3
此处需要重复status和status_numbers列
答案 0 :(得分:2)
您可以使用rollup
执行此操作:
select coalesce(job, 'Total') status, count(*) status_numbers,
coalesce(job, 'Total') status2, count(*) status_numbers2
from jobs
group by rollup(job)
order by grouping_id(job) desc;