Reputation: 3
I have data in two columns. I need to write a query that only shows the customers that have gone over their credit limit and by how much:
customer balance credit limit
418.75 500
10.75 200
200.1 100
Upvotes: 0
Views: 85
Reputation: 32690
Of course this doesn't take customer information into account since you didn't mention any customer tables, but this should get you the customer balance and overage:
SELECT customer_balance, credit_limit, customer_balance - credit_limit as overage
FROM your_table
WHERE customer_balance > credit_limit
It's pretty straight-forward; you select customers with a balance over their limit, and just select the difference as a third column.
Upvotes: 2