显示 table 中行下方的行总和
show sum of rows below rows in table
我有 table tblservicesummary
我有一个来自以下查询的结果集
select ss.Quantity as Qty ,ss.Item , ss.ES_ServiceStart as Time, fr.functionRoom from tblServiceSummary ss
join servdesc sd on ss.Service_time =sd.ServDescID
join funct fn on fn.FunctID = ss.FunctionID
join tbl_functionRoom fr on fr.id=fn.EvtID
where fn.StartDate between '2018-09-19' and '2018-09-19'
and ss.Item != ''
order by ss.Item
像这样
我想像
一样显示
表示行数据和行总和。
只是想知道这在 MySQL 中是否可行?我无法通过功能实现分组。
我发现的唯一相关的东西是汇总函数。
我试过了
类似
的查询
SELECT Quantity, Item, count(Quantity) AS sumoption
FROM tblServiceSummary
GROUP BY Quantity WITH ROLLUP
但这给了我这样的结果
也试过
SELECT Quantity, Item, count(Quantity) AS sumoption
FROM tblServiceSummary
GROUP BY Quantity WITH ROLLUP
请推荐
您可以与 "sum - group by item" select 合并并相应地排序。
select '' as Kind, ss.Quantity as Qty, ss.Item as Item,
ss.ES_ServiceStart as Time, fr.functionRoom
from tblServiceSummary ss
join servdesc sd on ss.Service_time =sd.ServDescID
join funct fn on fn.FunctID = ss.FunctionID
join tbl_functionRoom fr on fr.id=fn.EvtID
where fn.StartDate between '2018-09-19' and '2018-09-19'
and ss.Item != ''
union
select 'SUBTOTAL', sum(ss.Quantity), ss.Item, '', ''
from tblServiceSummary ss
join funct fn on fn.FunctID = ss.FunctionID
where fn.StartDate between '2018-09-19' and '2018-09-19'
and ss.Item != ''
group by ss.Item
order by Item, Kind
我有 table tblservicesummary
我有一个来自以下查询的结果集
select ss.Quantity as Qty ,ss.Item , ss.ES_ServiceStart as Time, fr.functionRoom from tblServiceSummary ss
join servdesc sd on ss.Service_time =sd.ServDescID
join funct fn on fn.FunctID = ss.FunctionID
join tbl_functionRoom fr on fr.id=fn.EvtID
where fn.StartDate between '2018-09-19' and '2018-09-19'
and ss.Item != ''
order by ss.Item
像这样
我想像
一样显示表示行数据和行总和。
只是想知道这在 MySQL 中是否可行?我无法通过功能实现分组。
我发现的唯一相关的东西是汇总函数。
我试过了
类似
的查询SELECT Quantity, Item, count(Quantity) AS sumoption
FROM tblServiceSummary
GROUP BY Quantity WITH ROLLUP
但这给了我这样的结果
也试过
SELECT Quantity, Item, count(Quantity) AS sumoption
FROM tblServiceSummary
GROUP BY Quantity WITH ROLLUP
请推荐
您可以与 "sum - group by item" select 合并并相应地排序。
select '' as Kind, ss.Quantity as Qty, ss.Item as Item,
ss.ES_ServiceStart as Time, fr.functionRoom
from tblServiceSummary ss
join servdesc sd on ss.Service_time =sd.ServDescID
join funct fn on fn.FunctID = ss.FunctionID
join tbl_functionRoom fr on fr.id=fn.EvtID
where fn.StartDate between '2018-09-19' and '2018-09-19'
and ss.Item != ''
union
select 'SUBTOTAL', sum(ss.Quantity), ss.Item, '', ''
from tblServiceSummary ss
join funct fn on fn.FunctID = ss.FunctionID
where fn.StartDate between '2018-09-19' and '2018-09-19'
and ss.Item != ''
group by ss.Item
order by Item, Kind