开发者

How to make a condition?

开发者 https://www.devze.com 2023-01-24 19:05 出处:网络
I have request SELECT IF(f.date_term=3,t.quarter*f.date_term ,\'\'), IF(f.date_term=6,t.halfyear*f.date_term,\'\'),

I have request

SELECT IF(f.date_term=3,t.quarter*f.date_term ,''),
       IF(f.date_term=6,t.halfyear*f.date_term,''),
       IF(f.date_term=12,t.year*开发者_Python百科f.date_term,'')

but this is not work.

how to make a condition? I need one value IF ( date_term == 3 ) {select quarter} ELSE IF ( date_term == 6) {halfyear} ....


Use a CASE expression:

SELECT CASE f.date_term
         WHEN 3 THEN t.quarter
         WHEN 6 THEN t.halfyear
         WHEN 12 THEN t.year
       END AS term_interval,
       ...

There's nothing to stop you from doing the calculation at the same time:

SELECT CASE f.date_term
         WHEN 3 THEN t.quarter * f.date_term
         WHEN 6 THEN t.halfyear * f.date_term
         WHEN 12 THEN t.year * f.date_term
       END AS term_calc,
       ...      
0

精彩评论

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