0
Date           Flight ID    Member ID   Seat Type   Seat Price  
2013-07-28     F71498           M69202          Business    RM 40.00

               F73591           M69202          First           RM 50.00
                                M69202          First           RM 50.00

               F71498           M37520          Business    RM 40.00
                                M69202          Business    RM 40.00
                                                            ===============
                                                            Total : ??
                                                            ===============

次のSQLを試しました

SELECT 
    r.ReservationDate, r.FlightID, r.MemberID, s.SeatType, s.SeatPrice
FROM 
    flight f, reservation r, seat s, member m
WHERE 
    r.FlightID = f.FlightID 
    AND r.SeatID = s.SeatID 
    AND r.MemberID = m.MemberID 
    AND ReservationDate = '2013-07-28' 
    AND s.FlightID = f.FlightID

必要に応じて上記のレポートを生成できますが、合計の合計SeatPriceを計算する方法を教えてください。合計の数え方を教えてください。高度なThx ... =)

4

1 に答える 1

0

私があなたを正しく理解していれば、以下のような結果セットが必要です。つまり、最後の行に合計列と合計の値があります

Date           Flight ID    Member ID   Seat Type   Seat Price  
2013-07-28     F71498        M69202      Business    RM 40.00

2013-07-28     F73591        M69202      First       RM 50.00
2013-07-28     F73591        M69202      First       RM 50.00

2013-07-28     F71498        M37520      Business    RM 40.00
2013-07-28     F71498        M69202      Business    RM 40.00

                                          Total      RM 220.0  

できるよ

SELECT 
    r.ReservationDate, r.FlightID, r.MemberID, s.SeatType, s.SeatPrice
FROM 
    flight f, reservation r, seat s, member m
    INNER JOIN reservation r
       ON r.FlightID = f.FlightID 
    INNER JOIN seat s
       ON r.SeatID = s.SeatID 
    INNER JOIN member m
       ON r.MemberID = m.MemberID
WHERE ReservationDate = '2013-07-28' 
      AND s.FlightID = f.FlightID

UNION

SELECT '','','','Total',SUM(s.SeatPrice)
FROM
FROM 
    flight f, reservation r, seat s, member m
    INNER JOIN reservation r
       ON r.FlightID = f.FlightID 
    INNER JOIN seat s
       ON r.SeatID = s.SeatID 
    INNER JOIN member m
       ON r.MemberID = m.MemberID
WHERE ReservationDate = '2013-07-28' 
      AND s.FlightID = f.FlightID
于 2013-07-29T05:33:33.567 に答える