sql查询想在同一类数据下面增加一行总计?
比如这样子。sql语句如下:SELECTsc.company,sum(e.expenditure_money)asexpenditure_money,se.`name`,...
比如这样子。sql语句如下:
SELECT sc.company,sum(e.expenditure_money) as expenditure_money,se.`name`,st.expenditure_type,e.create_time
FROM finance_expenditure e
LEFT JOIN system_company sc ON sc.id=e.company_id
LEFT JOIN system_expenditure_type st ON st.id=e.expenditure_type_id
LEFT JOIN system_employee se ON se.id=e.employee_id
GROUP BY sc.company,se.`name`,st.expenditure_type
union all
select '合计' as company,sum(e.expenditure_money),null as name,null as expenditure_type,null as create_time
FROM finance_expenditure e
LEFT JOIN system_company sc ON sc.id=e.company_id
GROUP BY sc.company
ORDER BY company
该怎么修改 展开
SELECT sc.company,sum(e.expenditure_money) as expenditure_money,se.`name`,st.expenditure_type,e.create_time
FROM finance_expenditure e
LEFT JOIN system_company sc ON sc.id=e.company_id
LEFT JOIN system_expenditure_type st ON st.id=e.expenditure_type_id
LEFT JOIN system_employee se ON se.id=e.employee_id
GROUP BY sc.company,se.`name`,st.expenditure_type
union all
select '合计' as company,sum(e.expenditure_money),null as name,null as expenditure_type,null as create_time
FROM finance_expenditure e
LEFT JOIN system_company sc ON sc.id=e.company_id
GROUP BY sc.company
ORDER BY company
该怎么修改 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询