SQL语句常用语法(开发场景中)

一、SQL语句常用小场景

1.查询某个表信息,表中某些字段为数据字典需要进行转义

SELECT
        t.ID,
        CASE
        WHEN t.DINING_TYPE = 1 THEN
        '早餐'
        WHEN t.DINING_TYPE = 2 THEN
        '午餐'
        WHEN t.DINING_TYPE = 3 THEN
        '晚餐'
        END AS diningTypeStr
from student t

2.联表查询语法

select si.* from student_info  si
left join classed_info ci on si.classed_id = ci.id 

3.每个xml中可以自定义一个查询语句头

  
    select ID, ORDER_NO, WX_ORDER_NO, SCHOOL_ID, GRADE_ID, CLASSES_ID, STUDENT_ID, STUDENT_PHONE,
    DINING_TYPE, FOOD_TYPE, PAY_TYPE, "STATUS", CREATE_ORDER_DATE_TIME, PAY_DATE_TIME,
    IS_DELETE, CREATOR, CREATE_TIME, MODIFIER, MODIFY_TIME from student_info
  

4.自定义查询语句


        
            and t.grade_id = #{gradeId, jdbcType=VARCHAR}
        
        
            and t.classes_id = #{classesId, jdbcType=VARCHAR}
        
    

5.批量新增


        
            INSERT INTO t_student_info (id, name)
            VALUES(#{item.id},#{item.name})
        
    

点赞加关注,持续更新中!!!

你可能感兴趣的:(Mysql,ORACLE,sql,数据库,mysql)