sql收集

find_in_set()
group_concat()
replace()
case when then   例如:  case  when section_name like ‘%一%‘ or section_name like ‘%1%‘ then 1
SUBSTRING_INDEX(now(), ,1)
insert into clazz_time_table (divide_clazz_id, section_name)
select #{divideClazzId,jdbcType=INTEGER}, section_name
FROM grade_time WHERE grade_id =1
配合唯一索引,存在就修改,不存在就新增
INSERT INTO clazz_time_table (clazz_time_table_id,section_name ,week1,week2)
VALUES
ON DUPLICATE KEY UPDATE
week1 = VALUES(week1),
week2 = VALUES(week2)
select  section_name,
    GROUP_CONCAT( CASE WHEN week1 != ‘‘ THEN LEFT ( course_name, 1 ) END ORDER BY course_name SEPARATOR / ) AS week1,
    GROUP_CONCAT( CASE WHEN week2 != ‘‘ THEN LEFT ( course_name, 1 ) END ORDER BY course_name SEPARATOR / ) AS week2,
    GROUP_CONCAT( CASE WHEN week3 != ‘‘ THEN LEFT ( course_name, 1 ) END ORDER BY course_name SEPARATOR / ) AS week3,
    GROUP_CONCAT( CASE WHEN week4 != ‘‘ THEN LEFT ( course_name, 1 ) END ORDER BY course_name SEPARATOR / ) AS week4,
    GROUP_CONCAT( CASE WHEN week5 != ‘‘ THEN LEFT ( course_name, 1 ) END ORDER BY course_name SEPARATOR / ) AS week5,
    GROUP_CONCAT( CASE WHEN week6 != ‘‘ THEN LEFT ( course_name, 1 ) END ORDER BY course_name SEPARATOR / ) AS week6,
    GROUP_CONCAT( CASE WHEN week7 != ‘‘ THEN LEFT ( course_name, 1 ) END ORDER BY course_name SEPARATOR / ) AS week7
    FROM
        course_time_table
        LEFT JOIN select_clazz_course USING ( select_clazz_course_id )
    WHERE
        select_id = #{selectId ,jdbcType=INTEGER}
    GROUP BY
        section_name
update select_clazz_course set
student_list = (CASE 
WHEN FIND_IN_SET(#{studentId,jdbcType=VARCHAR} ,`student_list`)
THEN TRIM(BOTH , FROM REPLACE(CONCAT(,,`student_list`,,),CONCAT(,,#{studentId,jdbcType=VARCHAR},,),‘‘)) END), current_num = current_num - 1 where select_clazz_course_id in (1,2,3,4)
    SELECT
    IF
        (
        sum( CASE WHEN is_teaching = 0 THEN 1 ELSE 0 END ) IS NULL,
        0,
        sum( CASE WHEN is_teaching = 0 THEN 1 ELSE 0 END )
        ) AS unTeachingCount
    FROM
        select_clazz_student
    WHERE
        select_id = #{selectId,jdbcType=INTEGER}
        AND teaching_classification_id IN (1,2,3,4)
         SELECT edu_vote.vote_id AS voteId,edu_vote.type_id AS typeId, edu_vote.user_name AS userName, edu_vote.title,edu_vote.content,edu_vote.school_id AS schoolId,edu_vote.participator_student_school AS participatorStudentSchool,
         edu_vote.participator_student_grade AS participatorStudentGrade,
         edu_vote.participator_student_clazz AS participatorStudentClazz,
        CASE WHEN @today = DATE(edu_vote.create_time)
            THEN CONCAT(今天 ,TIME_FORMAT(edu_vote.create_time, %H:%i))
            WHEN @yesterday = DATE(edu_vote.create_time)
            THEN CONCAT(昨天 ,TIME_FORMAT(edu_vote.create_time, %H:%i))
            WHEN @beforeyesterday = DATE(edu_vote.create_time)
            THEN CONCAT(前天 ,TIME_FORMAT(edu_vote.create_time, %H:%i))
            ELSE CONCAT(MONTH(edu_vote.create_time),"/",DAY(edu_vote.create_time), ,TIME_FORMAT(edu_vote.create_time, %H:%i)
            )END createTime,
        edu_vote.end_time AS endTime,
        edu_vote.sticky_state AS stickyState, edu_vote.vote_state AS voteState
        FROM edu_vote,
        (SELECT
          @today := CURRENT_DATE(),
          @yesterday := SUBDATE(CURRENT_DATE(), 1),
          @beforeyesterday := SUBDATE(CURRENT_DATE(), 2),
          @dd := TIME(NOW()),
          @bbs := MONTH(CURRENT_DATE())) sp
        WHERE (
            participator_student_school = #{schoolId,jdbcType=INTEGER}
            OR
            participator_student_grade LIKE CONCAT("%",#{gradeId,jdbcType=INTEGER},"%")
            OR
            participator_student_clazz LIKE CONCAT("%",#{clazzId,jdbcType=INTEGER},"%")
        )
        ORDER BY sticky_state DESC, create_time DESC

 

sql收集

上一篇:数据库分页


下一篇:JAVA开发ORACLE的规范