运行多个选择查询并将数据输出到相同的xml值中最合适的方法是什么?
SELECT
count(empID) as totalOrders
FROM
chandlerBrandLaunch
WHERE
orderStatus = 'Complete'
FOR XML PATH ('data'), TYPE, ELEMENTS, ROOT ('results');
SELECT
count(empID) as totalPayments
FROM
chandlerBrandLaunch
WHERE
paymentStatus = 'Complete'
FOR XML PATH ('data'), TYPE, ELEMENTS, ROOT ('results');
我的陈述是获得不同的数据计数以及WHERE子句的不同。
我只是希望能够为多个项目提取统计数据,并将其全部包含在一个输出中。
答案 0 :(得分:0)
如果有帮助,您可以在一个选择中同时选择:
SELECT
sum(case when empid is not null and orderStatus = 'Complete' then 1 else 0 end as totalOrders,
sum(case when empid is not null and paymentStatus = 'Complete' then 1 else 0 end as totalPayments
FROM
chandlerBrandLaunch