Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...You have made an incredible site which is truly a great help to me in solving problems. A tip of my hat to you!..."

Geography

Where in the world do Tek-Tips members come from?
Jony77 (IS/IT--Management)
22 Sep 08 4:20
Hello,

I am getting a wrong answer (lesser amount) after aggregation. The sum(quantity) in prod_fact_table is 2,089,033 but if I run the insert statement below the sum(quantity) in agg01_agg01_prod_fact_table will be 1,689,785 which is less. The two must be the same. Please what can be the problem? Any idea? See the insert statement below:

INSERT INTO agg01_prod_fact_table(
fact_count,
quantity,
machine_group_key,
location_key,
year,
quarter,
month,
day_of_month,
hour
)
SELECT
COUNT(*) AS fact_count,
SUM(BASE.quantity),
BASE.machine_group_key,
BASE.location_key,
DIM.year,
DIM.quarter,
DIM.month,
DIM.day_of_month,
DIM.hour
FROM prod_fact_table AS BASE, times AS DIM
WHERE DIM.times_key = BASE.times_key
GROUP BY
BASE.machine_group_key,
BASE.location_key,
DIM.year,
DIM.quarter,
DIM.month,
DIM.day_of_month,
DIM.hour;

Thanks,
Helpful Member!  blom0344 (TechnicalUser)
22 Sep 08 4:35
The obvious cause is , that by using an inner join, you are losing records from the facttable cause some times_key have no matching record from the BASE table.

Run the SQL using an outer join, like:

Quote:


INSERT INTO agg01_prod_fact_table(
fact_count,
quantity,
machine_group_key,
location_key,
year,
quarter,
month,
day_of_month,
hour
)
SELECT
COUNT(*) AS fact_count,
SUM(BASE.quantity),
BASE.machine_group_key,
BASE.location_key,
DIM.year,
DIM.quarter,
DIM.month,
DIM.day_of_month,
DIM.hour
FROM prod_fact_table AS BASE left outer join times AS DIM
on BASE.times_key = DIM.times_key
GROUP BY
BASE.machine_group_key,
BASE.location_key,
DIM.year,
DIM.quarter,
DIM.month,
DIM.day_of_month,
DIM.hour;

Ties Blom
 
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close