Hello Friends:
I have this query which is common to SQL as well as Oracle. Unfortunately, one of my clients complained that this query failed against their database. What actually surprised me that if I run this query against some
test database in Oracle, it works fine (in the sense, returns result if any) but running this on their database gives me an error
ORA-00979: not a GROUP BY expression with the second select statement highlighted.
Any insights on this?
select a.AccountID, a.AccountNumber,
(select AccountNumber from Account where AccountID =
a.MasterAccountID) MasterAccountNumber,
(select count(AccountID) from Account where MasterAccountID =
a.AccountID) hasChildren,
(select bs.Name from BillingSystem bs where bs.BillingSystemID =
a.BillingSystemID) BillingSystemName,
(select c.Name from Carrier c, BillingSystem bs where bs.BillingSystemID
= a.BillingSystemID and c.CarrierID = bs.CarrierID) CarrierName,
(select max(InvoiceNumber) from Invoice i, InvoiceAccount ia where
i.InvoiceID = ia.InvoiceID and ia.AccountID = a.AccountID
and i.InvDate = acct.maxdate) LastInvoice,
acct.maxdate as InvoiceDate
from Account a , (
select ia.accountid as acc, max(i.InvDate) maxdate from
InvoiceAccount ia, invoice i where ia.InvoiceID=i.InvoiceID
group by ia.accountid
) acct
where a.Accountid=acct.acc
and a.AccountID = 5 and a.Accepted = 0
I would be more than happy to offer any further details.
Sandeep