MySQL常用语句总结(长期更新)

  • A+
所属分类:MySQL 编程

此文章是日常开发中经常用到的sql语句,在这里记录一下,日后忘了方便查找,就不做基础讲解了,语句本就是一些基础语句,懂的人一看就懂了。

三表连查询

SELECT
    a.id,
    a.rank,
    a.GROUP,
    b.score1, 
    b.score2,
    b.score_avg,
    b.quarter,
    c.user_id,
    c.email,
    d.group_name
FROM
    y_grader a
    LEFT JOIN y_score b ON a.NAME = b.name
    LEFT JOIN jc_user c ON a.name = c.user_id
    LEFT JOIN jc_group d ON a.group = d.group_id
WHERE
    a.type=3
    and
    a.group=#{group}

根据年、月查询

SELECT
    * 
FROM
    y_task_information 
WHERE
    YEAR ( complete ) = 2018 
    AND MONTH ( complete ) = 8

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: