Subject | Re: SQL Help |
---|---|
Author | Svein Erling |
Post date | 2004-04-13T09:57:41Z |
What about something like:
SELECT A.ID, A.SID, SUM(A.VALUE)
FROM BURAK_TABLE A
WHERE A.BA = 'A'
GROUP BY A.ID, A.SID
HAVING SUM(A.VALUE) <>
(SELECT SUM(B.VALUE) FROM BURAK_TABLE B
WHERE B.BA = 'B' AND B.ID = A.ID AND B.SID = A.SID)
I must admit that I've never tried such a construct...
Set
SELECT A.ID, A.SID, SUM(A.VALUE)
FROM BURAK_TABLE A
WHERE A.BA = 'A'
GROUP BY A.ID, A.SID
HAVING SUM(A.VALUE) <>
(SELECT SUM(B.VALUE) FROM BURAK_TABLE B
WHERE B.BA = 'B' AND B.ID = A.ID AND B.SID = A.SID)
I must admit that I've never tried such a construct...
Set
--- In firebird-support@yahoogroups.com, Burak ÖZLER wrote:
> Hi all,
>
> I have a table at my application that all the modules(Documents
> at my app) inserts records to this table. The documents have three
> filed to determine the document at that common used table.
>
> the identifier field's are
>
> DOCUMNET_TYPE : INTEGER
> DOCUMENT_ID : INTEGER
> DOCUMENT_SID : INTEGER (this field for replication purposes to find
> where this document created.
>
> the table is lile this Let us call it common_table..
>
> COMMON_ID : INTEGER
> COMMON_SID : INTEGER
> DOCUMNET_TYPE : INTEGER
> DOCUMENT_ID : INTEGER
> DOCUMENT_SID : INTEGER (this field for replication purposes to find
> where this document is
> BA : CHAR (gets only 'B' AND 'A' VALUES)
> VALUE NUMERIC(18,4)
>
> the problem is when a document inserts to this table.
> must provide this.
> SUM(VALUE) 'B' = SUM(VALUE) 'A'
>
> User only pushes the post button and I insert the records about the
> document. A document can insert atleast 2 records and at most 8
> records to the table. The number of records that inserted is not
> important. The important think is to the record sum(Value) that have
> 'B' value at BA field must be equal to the records sum(value) that
> have A value at BA field.
>
> And the question..
>
> I want to write an sql than returns me the document type,ID,SID
> fields distinctly that where this equality crashes?
>
> Any help will be very valuable..
>
> With my best regards
> Burak OZLER