• mysql 临时变量,临时表


    创建临时表 CREATE TEMPORARY TABLE tmp_table ```

    CREATE TEMPORARY TABLE tmp_table SELECT * FROM  `tb_fdt_courseitem` WHERE `StudentId`='0e02d67f-02ba-4cb7-87de-d5e1d4dcfa8e'
    AND  `StartDate`>='2012-01-01'
    AND `EndDate`<='2013-12-31'
    GROUP BY   `SubjectId`;

    查询
    SELECT * FROM tmp_table;

    删除
    DROP TEMPORARY TABLE IF EXISTS tmp_table;

    1. -- Mysql 存储过程
    2. /* 
    3. set @result = 0; 
    4. create procedure login(     -- 定义参数,有in、out、inout三种类型
    5. in user varchar(10), 
    6. in pass varchar(10), 
    7. out result int
    8.     ) 
    9. begin
    10. declare passd varchar(10);-- declare 声明临时变量、类型,然后用set 进行赋值,declare 临时变量只能放在begin end 区域中,而其作用域也只是在begin end 中, 而 set @ 定义的变量是全局变量
    11. select password into passd from login where username=user; 
    12.         if passd like pass then --  If 语句,后面要加上 End IF,就像是case 后也要加 End Case  一样
    13. select 'Login Success' as Massage; 
    14. set result = 1; 
    15. else
    16. select 'Login Failed' as Message; 
    17. set result =0; 
    18. end if; 
    19. end; 
    20. */ 
    21. -- 调用存储过程  call login('root','root',@result);
    22. -- 删除存储过程  drop procedure login
    23. create procedure translate( 
    24.     id int
    25. begin
    26. case id 
    27. when 1 then
    28. select 'one' as trans; 
    29. when 2 then
    30. select 'two' as trans; 
    31. when 3 then
    32. select 'three' as trans; 
    33. else
    34. select 'no trans' as trans; 
    35. end case; 
    36. end; 
    37. /* 
    38. case 用法有两种: 
    39.     1. 条件变量在when 中 
    40. select name, case
    41. when age>10 then xxxxx 
    42. else
    43.                 xxxxxx 
    44. end case
    45.     2. 条件变量在case 中 
    46. select name,case age 
    47. when >10 then xxx  
    48. else xxxxxs 
    49. end case
    50. */ 

    //再来一个演示

    1. BEGIN   
    2.     DECLARE long_status VARCHAR(20);   
    3.     IF in_status = 'O' THEN   
    4.         SET long_status='Overdue';   
    5.     ELSEIF in_status = 'U' THEN   
    6.         SET long_status='Up to date';   
    7.     ELSEIF in_status = 'N' THEN   
    8.         SET long_status='New';   
    9.     END IF;   
    10.     RETURN(long_status);   
    11. END; 

    //给指定时间,增加一天

    DATE_ADD(OrderDate,INTERVAL 1 DAY)

    //指定时间,转换为 年月日

    DATE_FORMAT(p_time,'%Y-%m-%d')

  • 相关阅读:
    巧用table的rules属性设置表格的边框掩饰。。。
    JS日期和时间
    onchange事件验证文本框格式,不正确光标返回原文本框,这个js怎么写?
    简易万用表
    在单片机中的空函数
    地感线圈的讲究
    全桥片
    这个当单片机程序怎么会不停的通过串口发数据,设置波特率为9600,但是串口软件接受数据不对(初学者,请高手指教)
    今天开博
    关于二极管
  • 原文地址:https://www.cnblogs.com/joeylee/p/2842287.html
Copyright © 2020-2023  润新知