我正在寻找一种更优雅(可能更快)的解决方案来解决我的困境。
我有以下查询来生成关于呼叫流量表的报告:
SELECT 'Tariff1' as [Tariff], Count([Number]) as [Number of calls] ,sum(convert(bigint,[Seconds]))/60 as [Minutes], sum([CustomerCost]) as [Customer Cost], sum([WholesaleCost]) as [WholesaleCost]
FROM [MarchCalls]
where [AccNo] in (select [accno] from [Tariffs] where [Tariff] = 'Tariff1')
union
SELECT 'Tariff2' as [Tariff], Count([Number]) as [Number of calls] ,sum(convert(bigint,[Seconds]))/60 as [Minutes], sum([CustomerCost]) as [Customer Cost], sum([WholesaleCost]) as [WholesaleCost]
FROM [MarchCalls]
where [AccNo] in (select [accno] from [Tariffs] where [Tariff] = 'Tariff2')
union
SELECT 'Tariff3' as [Tariff], Count([Number]) as [Number of calls] ,sum(convert(bigint,[Seconds]))/60 as [Minutes], sum([CustomerCost]) as [Customer Cost], sum([WholesaleCost]) as [WholesaleCost]
FROM [MarchCalls]
where [AccNo] in (select [accno] from [Tariffs] where [Tariff] = 'Tariff3')
union
SELECT 'Total' as [Tariff], Count([Number]) as [Number of calls] ,sum(convert(bigint,[Seconds]))/60 as [Minutes], sum([CustomerCost]) as [Customer Cost], sum([WholesaleCost]) as [WholesaleCost]
FROM [MarchCalls]
几点: 由于记录量和其中的数字,需要转换(bigint) 返回的记录集必须保持这种格式 此数据(和数据库)是严格只读的 SQL server 2012
这个查询在每个月底需要更长的时间,我需要减少时间
谁能帮我简化这个?