mysql update加減||select操作同一表


               
MySQL         FROM         ,                  ,  FROM                ,             。
      ,         ,                 ,   if     。

        
 update  goods set goods_number =(select if(100>gb,0,gb-100) from (select goods_number as gb from goods where goods_id=2 ) as gb  ) where goods_id=2
 
    

update  goods set goods_number =(if(goods_number>100,goods_number-100,0) )where goods_id=2


 
       update apples  
   set price = (  
      select price from (  
         select * from apples  
      ) as x  
      where variety = 'gala')  
   where variety = 'test';

if when

SELECT CASE 1 WHEN 1 THEN 'one'

    ->     WHEN 2 THEN 'two' ELSE 'more' END;

        -> 'one'

mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;

        -> 'true'

mysql> SELECT CASE BINARY 'B'

    ->     WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;

        -> NULL


mysql> SELECT IF(1>2,2,3);

        -> 3

mysql> SELECT IF(1<2,'yes ','no');

        -> 'yes'

mysql> SELECT IF(STRCMP('test','test1'),'no','yes');

        -> 'no