开发者

How do I calculate the difference

开发者 https://www.devze.com 2023-03-06 14:53 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消