gpt4 book ai didi

mysql - 使用条件语句连接多个表

转载 作者:行者123 更新时间:2023-11-30 00:27:06 25 4
gpt4 key购买 nike

我有 3 个这样的 mysql 表:

enter image description here enter image description here

基于该表,我想制作一个带有条件语句的表:如果表 3 中的 skor >= nilai,则 saran = 表 2 中的市长和次要,否则则 saran = 表 1 中的 butuh,其值大于 0,并由 bidang 连接。对于nilai =

selct((max(skor)-min(skor))*0.25)+min(skor) from table 3

所以,结果是这样的:

enter image description here

如何制作这个?

最佳答案

尝试以下查询:

select
NIP,
Bidang,
case when Skor >= ((max(skor)-min(skor))*0.25)+min(skor)
then concat(mayor,',',minor)
else concat(Butuh,',',Bidang)
end as Saran
from
(
select table2.*,
table1.Butuh,
table1.Kurang,
table3.Skor
from table2 join table1
on table2.Bidang = table1.Bidang
left join table3
on table2.NIP = table3.NIP
where table1.Butuh > 0
) tab

关于mysql - 使用条件语句连接多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22787340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com