Article View: borland.public.interbase.sql
Article #417Re: Error with Subquery and Group By
From: Arno Brinkman
Date: Fri, 07 Mar 2008 08:52
Date: Fri, 07 Mar 2008 08:52
43 lines
2420 bytes
2420 bytes
Hi, > select a.o_csoc, a.o_nreserc, a.o_conto, a.o_sezio, a.o_curcytot, > a.o_curcynaz, max(a.o_percam), > sum(a.o_prnzdr) - sum(a.o_prnzav) Sdo_Naz, > sum(a.o_prexdr), sum(a.o_prexav), > sum(a.o_prnzdr), sum(a.o_prnzav), > (select b1.nicknm from sezio b1 where b1.csoc = a.o_csoc and > b1.nreserc = a.o_nreserc and b1.csez = a.o_sezio and > b1.fdel = '0' ) as DescrSezio > from SDICOGE (:csoc ,: abinp , :fil , :lastdata , :allambfil ) a > group by a.o_csoc, a.o_nreserc, a.o_conto, a.o_sezio, > a.o_curcytot, a.o_curcynaz > order by a.o_csoc, a.o_nreserc, a.o_conto, a.o_sezio, a.o_curcytot > > If I remove sum fields and group by clause query works. > If I remove subquery , query works. > > Which is the conflict ? Your query looks fine, but for some reason InterBase seems not to be able to handle it. There are some workarounds you can try - put an aggregate function around the sub-select (MIN / MAX) - put an aggregate function around b1.nicknm (MIN / MAX) - move the sub-select into the from clause as an LEFT JOIN and group on b1.nicknm too Regards, Arno Brinkman ABVisie -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Firebird open source database with many powerful SQL features: http://www.firebirdsql.org http://www.firebirdsql.info General database developer support: http://www.databasedevelopmentforum.com Support list for Interbase and Firebird users: firebird-support@yahoogroups.com Nederlandse firebird nieuwsgroep: news://newsgroups.firebirdsql.info
Technical Details
Message-ID:
<47d10264@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<47cec8df$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,5277ddb39d374d09 X-Google-Attributes: gid114a0e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Arno Brinkman" <bnewsgroups @ REMOVE_ME abvisie.nl> Newsgroups: borland.public.interbase.sql References: <47cec8df$1@newsgroups.borland.com> Subject: Re: Error with Subquery and Group By Date: Fri, 7 Mar 2008 09:52:46 +0100 Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 84.81.40.49 Message-ID: <47d10264@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1204879972 84.81.40.49 (7 Mar 2008 00:52:52 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail