总和与众不同不会改变结果吗? [英] Sum and distinct dont alter results?

查看:64
本文介绍了总和与众不同不会改变结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手,目前为止还没有运气,非常感谢!

I am a novice trying to work through this here with no luck so far, any help is greatly appreciated!!!

Select Distinct
   (AB.agency_no || '-' || ab.branch_no) AS "AGENCY-BRANCH",
   count (AB.agency_no || '-' || ab.branch_no) AS Occurences,
   A.AGY_NAME AS AGENCY,
   Sum(AB.annual_premium) as Premium
 From Agency_Book_View AB, Agency A, Branch B
 Where AB.agency_no = A.Agency_No
   AND B.EXPIRATION_DATE = TO_DATE('12-31-2078', 'MM-DD-YYYY')
   AND B.EFFECTIVE_DATE <= sysdate and b.effective_date >=sysdate - 364
 Group by AB.agency_no || '-' || ab.branch_no, A.Agy_Name, ab.annual_premium
 Order by AB.agency_no || '-' || ab.branch_no

所以我想返回每个机构分支机构的年度总保费,我是多次发生机构分支。我正在设法使每个代理商分支机构只有一条生产线。我希望这很清楚。我试图包含结果集,但不允许在帖子中包含图片。

So I am trying to return total annual premium per "agency-branch" and I am getting multiple occurrences of agency-branch. I am trying to get one line per agency branch. I hope this is clear. I tried to include a result set but wasnt allowed to include a picture in my post.

非常感谢!

布拉德

推荐答案

尝试一下:

SELECT (AB.agency_no || '-' || AB.branch_no) AS "AGENCY-BRANCH",
    COUNT(AB.agency_no || '-' || AB.branch_no) AS Occurences,
    A.AGY_NAME AS AGENCY,
    SUM(AB.annual_premium) AS Premium
FROM Agency_Book_View AB, Agency A, Branch B
WHERE AB.agency_no = A.Agency_No AND AB.branch_no = B.branch_no
  AND B.EXPIRATION_DATE = TO_DATE('12-31-2078', 'MM-DD-YYYY')
  AND B.EFFECTIVE_DATE <= SYSDATE AND B.effective_date >= SYSDATE - 364
GROUP BY AB.agency_no || '-' || AB.branch_no, A.Agy_Name
ORDER BY AB.agency_no || '-' || AB.branch_no

我加入了B表和AB表,删除了DISTINCT和GROUPED BY ab.annual_premium

I joined B table and AB table, removed the DISTINCT and the GROUPed BY ab.annual_premium.

这篇关于总和与众不同不会改变结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆