473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

summary aggregate information from a second table

Hi,

I have two tables and I want to get summary information from the second table for each row of the first table, I can see two ways to do this one is with the SQL below but since the first table is very big the group by takes along time and there is no need since it is unique. The second way is witha function which loops through each row in the first table and does the aggregate function for that row. Does anyone know of a way to do this with SQL or will I have to use a function?

Thanks in advance
Matthew
EXPLAIN select ID, MIN( AA.ALLOCATION - AA.BOOKING_LEVEL ), COUNT(1)
FROM package_rules_expanded PRE, ACCOMMODATION_AVAILABILITY AA
WHERE AA.CODE = ACCOMM_CODE AND AA.CODE_TYPE = ACCOMM_CODE_TYPE
AND AA.ROOM_TYPE = PRE.ROOM_TYPE
AND AA.DATE BETWEEN OUTWARD_DATE AND ( RETURN_DATE - 1 )
GROUP BY ID;

Aggregate (cost=23229579.28..23641565.44 rows=4119862 width=78)
-> Group (cost=23229579.28..23435572.36 rows=41198616 width=78)
-> Sort (cost=23229579.28..23332575.82 rows=41198616 width=78)
Sort Key: pre.id
-> Merge Join (cost=893507.72..10179309.28 rows=41198616 width=78)
Merge Cond: (("outer".accomm_code = "inner".code) AND ("outer".room_type = "inner".room_type) AND ("outer".accomm_code_type = "inner".code_type))
Join Filter: (("inner".date >= "outer".outward_date)AND ("inner".date <= ("outer".return_date - 1)))
-> Sort (cost=80147.71..81166.21 rows=407400 width=38)
Sort Key: pre.accomm_code, pre.room_type, pre.accomm_code_type
-> Seq Scan on package_rules_expanded pre (cost=0.00..28271.00 rows=407400 width=38)
-> Sort (cost=813360.01..823216.61 rows=3942640 width=40)
Sort Key: aa.code, aa.room_type, aa.code_type
-> Seq Scan on accommodation_availability aa (cost=0.00..77409.40 rows=3942640 width=40)

Nov 22 '05 #1
0 1393

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Greg Stark | last post by:
I find I often want to be able to do joins against views where the view are aggregates on a column that has an index. Ie, something like SELECT a.*, v.n FROM a JOIN (select a_id,count(*) as n...
1
by: sausage31 | last post by:
I have a table as follows.... Device LotID Result1 Result2 Result3 aaa 1 5 10 15 bbb 1 2 4 6 aaa 2 ...
3
by: MrNobody | last post by:
I've read that the expression property for DataColumns is used to "Sets or retrieves the expresssion used to filter rows, calculate the values in a column, or create an aggregate column.". I...
2
by: rodchar | last post by:
hey all, i was wondering how you would do this. i have a webform with a summary page on it. The summary page tells you the followng: # of Employees Unchanged # of Employees Underwriting #...
1
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.