MySQL Forums
Forum List  »  Analytics, Reporting, BI

Create custom field with database snapshot changes
Posted by: Sergei Petrov
Date: November 10, 2015 09:44AM


I am designing an SQL query to power a report for our team and have an issue with a slightly tricky custom field. I'm not an SQL expert so this might sound like basic stuff to some of you but here it is:

We have a database that saves daily snapshots of financial data - call them database_yesterday and database_today. I need a field that spells out what has changed between the two snapshots.

For example, there are several fields that I track for changes - say these are deal value and contact date. When one or more of these changes between the two snapshots, the entry appears in the list.

I need to create a column that calls out these changes. For example, if the deal value was increased by $20,000 that field would say "Deal Value increased by $20,000". Or if the deal value decreased by $5,000 AND the contract date was changed from 10/11/2015 to 15/11/2015 it would say "Deal Value decreased by $5,000 and contract date changed from 10/11/2015 to 15/11/2015".

What would be the cleanest way to design a query that populates this field? I know I can probably do it with a bunch of nested IF statements but it would be very long and messy.

Thanks in advance.

Options: ReplyQuote

Written By
Create custom field with database snapshot changes
November 10, 2015 09:44AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.