sql if else

1.oracle

Now the definition of a table named Output, which respectively define two column monthid (var type) and sale (Number type), if the sale value of D = 1000 Translation, 2000 = Translation is C, when translated into B = 3000 , when translated into A = 4000, in the case of other values ​​other translation;

SQL as follows:

Select monthid , decode (sale,1000,'D',2000,'C',3000,'B',4000,'A',’Other’) sale from output

sign () function in accordance with a value of 0, positive or negative, respectively, return 0,1, -1,

If you take the smaller value is

select monthid, decode (sign (sale-6000), - 1, sale, 6000) from output, i.e., the purpose of taking a smaller value.

select decode (sex, male, 1,0), decode (sex, female, 1,0) from the table

2.mysql

 

    1.case when then
    如:Select title,case Emergency when 1 then '紧急'  else '普通' End  as  emergency   from already_sign

    Can not be greater than the above embodiment when less than the number

    The following can be

    SELECT NAME,CASE  WHEN score<70 THEN '过' ELSE '不过' END AS mark FROM course



    2.if
    如:select a.title,if(a.Emergency=1,'紧急','普通')emergency from already_sign a

    SELECT NAME, IF (score> 60, 'over', 'but') mark FROM course

      

Guess you like

Origin www.cnblogs.com/jentary/p/11585134.html