Tuesday 25 September 2018

mysql memo - if else

こんにちは〜。
今日はmysql memoです。メモメモ。。

if elseを使いたい!

こう使います。

 select p_name, p_price, if (p_price > 100.0, 'A lank', 'B lank') as result from products;

caseを使いたい!

 select p_product,
           p_price,
           case floor(p_price) % 2
             when 0 then 'even'
             when 1 the 'odd'
             else null
          end as type
 from products;

caseを使いたい2!

 select
   p_product,
   p_price,
   case
     when p_price > 100.0 then 'A level'
     when p_price > 80.0 then 'B level'
     else 'C level'
   end as type
  from produces;


↓来て頂きありがとうございます。クリックしていただくと、励みになります。↓
にほんブログ村 IT技術ブログ IT技術メモへ
にほんブログ村

No comments:

Post a Comment