我有3个mysql表,如下所示:




基于该表,我想用条件语句制作一个表:
如果表3中的skor> = nilai,则saran =市长,表2中的未成年人,否则saran =表1中的值大于0的值,由bitang连接。对于汝来=

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


因此,结果如下:



怎么做?

最佳答案

请尝试以下查询:

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/

10-14 13:53