如何在单个SQL语句(MySQL)中组合if语句?

编程入门 行业动态 更新时间:2024-10-26 19:41:12
本文介绍了如何在单个SQL语句(MySQL)中组合if语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我坚持使用包含以下计算的SQL语句: 我在我的数据库中有三个表foto 1.rates(rate_id,price,frequency),2.rate_changes(old_rate_id,new_rate_id,photographer_id)和付款(创建,amount_net) 此外,我想根据价格频率计算每月的amount_net,但我不确切知道该怎么做:

hi everyone, I´m stuck on a SQL statement which contains the following calculation: I have three tables in my database foto 1.rates (rate_id, price, frequency),2.rate_changes (old_rate_id, new_rate_id, photographer_id) and payments (created, amount_net) Further, I want to calculate the amount_net per month depending on the rate frequency but I dn´t know exactly how to do it:

SELECT sum( if foto.rates.frequency = 1 then (sum foto.payments.amount_net(month x)) elseif foto.rates.frequency = 3 then (foto.payments.amount_net (month x)/foto.rates.frequency) And foto.payments.amount_net (month x-2)+foto.payments.amount_net (month x)/foto.rates.frequency, foto.payments.amount_net (month x-1) + foto.payments.amount_net (month x)/foto.rates.frequency elseif foto.rates.frequency = 6 then..(the same calculation as in the case before) elseif foto.rates.frequency = 12 then..(the same calculation as in the cases before)) End

非常感谢您的帮助!

Thanks a lot in advance for your help!

推荐答案

您好, 如何尝试使用某个功能?这对你想要达到的结果很有帮助。 Hello, How about trying to use a function? That would be helpful in the result you want to achieve.

更多推荐

如何在单个SQL语句(MySQL)中组合if语句?

本文发布于:2023-10-22 23:58:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   组合   如何在   SQL   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!