Solved

How to count by outer group in Oracle?

Posted on 2008-09-29
2
471 Views
Last Modified: 2013-11-11
How to count by outer group? I mean
when I use count now, it count the number of records in the group po.po_nbr, pt.pt_part.

By I just want to count the group po.po_nbr and appear in the "Number of Record" column, how to do that?
SELECT po.po_nbr "PO Number", pt.pt_part "Part Number", COUNT(pt.pt_part) "Number of Record", CEIL(COUNT(pt.pt_part) / 9) "Total Page"
FROM {mfgotrng}.QAD.PO_MSTR po, {mfgotrng}.QAD.POD_DET pod, {mfgotrng}.QAD.PT_MSTR pt
WHERE po.po_domain = pod.pod_domain AND pod.pod_domain = pt.pt_domain AND po.po_nbr = pod.pod_nbr AND pod.pod_part = pt.pt_part
AND pod.pod_type <> 'm'
GROUP BY po.po_nbr, pt.pt_part

Open in new window

0
Comment
Question by:mawingho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 22608924
SELECT po.po_nbr "PO Number", pt.pt_part "Part Number", COUNT(*) over (partition by po.po_nbr) "Number of Record" , CEIL(COUNT(pt.pt_part) / 9) "Total Page"
FROM {mfgotrng}.QAD.PO_MSTR po, {mfgotrng}.QAD.POD_DET pod, {mfgotrng}.QAD.PT_MSTR pt
WHERE po.po_domain = pod.pod_domain AND pod.pod_domain = pt.pt_domain AND po.po_nbr = pod.pod_nbr AND pod.pod_part = pt.pt_part
AND pod.pod_type <> 'm'
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 22608945
or maybe this...

select  po_nbr "PO Number", pt_part "Part Number", cnt "Number of Record", CEIL(cnt / 9) "Total Page"
from
(
SELECT po.po_nbr , pt.pt_part , COUNT(*) over (partition by po.po_nbr) cnt
FROM {mfgotrng}.QAD.PO_MSTR po, {mfgotrng}.QAD.POD_DET pod, {mfgotrng}.QAD.PT_MSTR pt
WHERE po.po_domain = pod.pod_domain AND pod.pod_domain = pt.pt_domain AND po.po_nbr = pod.pod_nbr AND pod.pod_part = pt.pt_part
AND pod.pod_type <> 'm')
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to recover a database from a user managed backup

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question