[英]how to use sum function when there are multiple rows
MSISDN Name y/N top cycle ActivationDate Bottom Provisioned renewdate
78 W1 N NA 24 3-Apr-15 th4 512 10-Apr-15
78 W1 N NA 24 3-Apr-15 th5 256 17-Apr-15
78 W1 N NA 24 3-Apr-15 th2 512 5-Apr-15
79 w2 Y 33 29 4-Apr-15 th5 1024 8-Apr-15
79 w2 Y 33 29 4-Apr-15 th4 2048 8-Apr-15
Expected output 预期产量
MSISDN Name y/N top cycle ActivationDate Bottom Provisioned renewdate
78 W1 N NA 24 3-Apr-15 null 1280-2048 null
79 w2 Y 33 29 4-Apr-15 th5 1024 8-Apr-15
79 w2 Y 33 29 4-Apr-15 th4 2048 8-Apr-15
when i write a sql i am able to query the sql for NA case grouping based on the name. 当我编写一个sql时,我能够根据名称查询该sql以进行NA案例分组。 can we write a sql to meet the both conditions.when "NA" it has to sum up all the data provisioned 我们可以编写一个满足这两个条件的sql吗?“ NA”时,它必须汇总所有已配置的数据
You can use a UNION to do this: 您可以使用UNION来执行此操作:
SELECT MSISDN, Name, y/N, top, cycle, activationDate, NULL, Sum(PRovisioned), Null
FROM <table>
WHERE top = 'NA'
GROUP BY MSISDN, Name, y/N, top, cycle, activationDate
UNION ALL
SELECT MSISDN,Name,y/N,top,cycle,ActivationDate,Bottom,Provisioned,renewdate
FROM <table>
WHERE top <> 'NA'
That should get you close. 那应该让你接近。 I have no idea how you are getting 1280-2048
for your 'Provisioned' in the GROUP BY
query though. 我不知道您如何在GROUP BY
查询中获得1280-2048
的“ Provisioned”。 You'll have to explain the logic there for additional help should you need it. 您需要在此处解释逻辑以获取其他帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.