Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 447

Calculating a value by summing several rows

$
0
0

Table contains data about hotel rooms.

We can see the same Room available for different date periods - at different Prices. AccmdMenTypeCode - is the Code that shows how many people can stay in this type of room.

A person wants to stay in the room from 2025-01-05 to 2025-04-01 (87 days).I already calculated OverlapDaysCount field that shows days count for every date period between Start and End.Now we need to have all the cases when we can accomodate the person in the room for 87 days. And calculate the Price for the Room.

IdHotelCodeAccomodationPeriodBeginAccomodationPeriodEndRoomTypeAccmdMenTypeCodePriceOverlapDaysCount
1MONTE2025-01-102025-03-10DGV010100039960
2MONTE2025-01-102025-03-10DGV010100039960
3MONTE2025-03-062025-05-14DGV0101000310627
4MONTE2025-03-062025-05-14DGV0101000310627
5MONTE2024-07-012025-07-15DGV0101000310987
6MONTE2024-07-012025-07-15DGV0101000310987
7MONTE2025-01-102025-03-10DGV010103129960
8MONTE2025-01-102025-03-10DGV010103129960
9MONTE2025-03-062025-05-14DGV0101031210627
10MONTE2025-03-062025-05-14DGV0101031210627
11MONTE2024-07-012025-07-15DGV0101031210987
12MONTE2024-07-012025-07-15DGV0101031210987

For example, he can stay for 60 days (till 2025-03-10) in the Room with Id = 1 at Price 99, then in the Room with Id = 3 for 27 days at Price 106.

In total, Price will be (60 * 99) + (27 * 106) = 8,802

OR he can stay in the Room with Id = 5 all the 87 days, but with Price of 109 - in total it will be 87 * 109 = 9,483

We need to offer him all the possible options so that he can choose.Expected request result would be something like this

HotelCodeRoomTypeAccmdMenTypeCodeTotalPriceOverlapDaysCount
MONTEDGV01010003880287
MONTEDGV01010003948387
MONTEDGV01010312948387

Here is the table with the data. I try very hard, but it doesn't work either. I'm sure that I need to change my approach.

Any ideas?


Viewing all articles
Browse latest Browse all 447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>