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_LEVE L ), COUNT(1)
FROM package_rules_e xpanded PRE, ACCOMMODATION_A VAILABILITY AA
WHERE AA.CODE = ACCOMM_CODE AND AA.CODE_TYPE = ACCOMM_CODE_TYP E
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".accom m_code = "inner".cod e) AND ("outer".room_t ype = "inner".room_ty pe) AND ("outer".accomm _code_type = "inner".code_ty pe))
Join Filter: (("inner".dat e >= "outer".outward _date)AND ("inner".dat e <= ("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_e xpanded pre (cost=0.00..282 71.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_a vailability aa (cost=0.00..774 09.40 rows=3942640 width=40) 0 1416 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 group by a_id) as v USING (a_id)
where there's an index on b.a_id. assume there are other tables being joined
so I can't just move the aggregate to the outermost layer.
|
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 6 9
I need to determine the mean of all results for each LotID, so used
the Row Average function described on the Microsoft Knowledge base,
which gives
|
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 have seen examples on how to filter a column, but how would I filter out
an entire row depending on the value of a column?
For example, if I wanted to filter out every row in a multi-column table
where the "Is Fubar" column equals "true", how would...
|
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
# of Employees Approved
|
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
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |