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
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.
精彩评论