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 |