Am interested to know how correct is my query the question is posted here., I doubt If I have written a perfect one, and I wish to ask you all where can I improve my code.
Note: I did not want to fill this place up with lot of code, was very brief. Thank you.
SELECT a.BookingId AS BookingId,
CAST(b.TransactionDateTime AS DATE) AS TransactionDate
FROM TC33_AuditTrial A
JOIN TC33_AuditTrial b
ON a.AuditId = b.AuditId
WHERE a.TransactionType = 'S'
AND CAST(a.TransactionDateTime AS DATE) =
(SELECT CAST(b.TransactionDateTime AS DATE)
FROM TC33_AuditTrial b
WHERE b.BookingId = a.BookingId
AND b.AuditId =
(SELECT MAX(b.AuditId)
FROM TC33_AuditTrial b
WHERE a.BookingId = b.BookingId
AND b.TransactionType = 'R'
)
)
AND a.TransactionValue =
(SELECT SUM(b.TransactionValue)
FROM TC33_AuditTrial b
WHERE a.BookingId = b.BookingId
AND b.TransactionType = 'R'
)