Given a customerBalance table with three columns: name, date and balance. Assume a set of records, such as:
cus_name cus_date cus_balance John 06/14/2011 1000 John 06/15/2011 500 John 06/16/2011 0 Mary 06/14/2011 3000 Mary 06/15/2011 2800 Mary 06/16/2011 0
How to create a SQL query that returns for date 6/16/2011 instead of 0, the last non-zero value based on the date (in the example, $ 500 for John and $ 2,800 for Mary)?
I am trying to do this using a subquery that uses the Max function to get the latest date with a non-zero value, but I have failed. This example is pretty โpointless", but I really need to do such an operation in my dataset. Thanks!
source share