dbTalk Databases Forums  

SQL question - how to compare two summarized tables

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss SQL question - how to compare two summarized tables in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Edgard L. Riba
 
Posts: n/a

Default SQL question - how to compare two summarized tables - 09-24-2009 , 09:40 AM






Hi,

I can't figure this out.

I have two tables. Roughly:

CREATE TABLE iSales (
SalesDate DATE NOT NULL,
StoreNum INT NOT NULL,
SequenceId INT NOT NULL,
Barcode VARCHAR(18),
SaleAmount DECIMAL(10,5),
PositiveFlag INT,
PRIMARY KEY (SalesDate,StoreNum,SequenceId,Barcode)
);

and

CREATE TABLE iSalesByDepartment (
SalesDate DATE NOT NULL,
StoreNum INT NOT NULL,
DepartmentId INT NOT NULL,
TimePeriod INT NOT NULL,
Barcode VARCHAR(18),
SaleAmount DECIMAL(10,5),
PositiveFlag INT,
PRIMARY KEY (SalesDate,StoreNum,DepartmentId,TimePeriod,Barcod e)
);

I need to compare:

SELECT a.Barcode,SUM(a.SaleAmount*a.PositiveFlag) FROM iSales
WHERE a.SalesDate = '2009-09-23' AND a.StoreNum=4
GROUP BY a.Barcode

to

SELECT b.Barcode,SUM(b.SaleAmount*b.PositiveFlag) FROM iSalesByDepartment
WHERE b.SalesDate = '2009-09-23' AND b.StoreNum=4
GROUP BY b.Barcode

In other words I need to summarize both tables by barcode, and list those
Barcodes which have differences between the two tables. Each table has a
different number of records per barcode. One has one record per sale
transaction, and the other has one record per time period.

I don't know what's wrong with me today, but I can't figure this out <g>...
Thanks in advance,
Edgard

BTW. I use ASA9

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.