Solved

How to count by outer group in Oracle?

Posted on 2008-09-29
2
458 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
  • 2
2 Comments
 
LVL 73

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 73

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
UNIX SCP 5 49
Convert Oracle data into XML document 2 39
report returning null 21 52
Oracle and DateTime math 6 16
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
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 video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now