日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql常用语句整理

發布時間:2025/4/16 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql常用语句整理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.查看表中是否有字段值重復:

select * from user_num group by user HAVING count(user)>=2

2.函數作為查詢的條件

select * from 表名 HAVING SUM(字段名) = SUM(字段名);

或者

select * from 表名? group by 排序字段HAVING SUM(字段名) = SUM(字段名)

3.在數據庫的使用中,有時候可以使用視圖來簡化sql語句

創建視圖的語句如下:

create view view_name as select??字段名 from 表名? group by? 排序字段 ,排序字段

4.通過生日計算年齡的sql:

  • select??
  • ????id,??
  • ????DATE_FORMAT(birthday,"%Y-%m-%d")?birthday,??
  • ????CURDATE()?,??
  • ????(year(now())-year(birthday)-1)?+?(?DATE_FORMAT(birthday,?'%m%d')?<=?DATE_FORMAT(NOW(),?'%m%d')?)?as?age??
  • from??
  • ????t_user?where?id?in?(1,55000,55001);
  • 4.通過身份證號碼查詢用戶的地址和年齡

    select? case left(member_idcard,2)
    when '11' then '北京市'
    when '12' then '天津市'
    when '13' then '河北省'
    when '14' then '山西省'
    when '15' then '內蒙古自治區'
    when '21' then '遼寧省'
    when '22' then '吉林省'
    when '23' then '黑龍江省'
    when '31' then '上海市'
    when '32' then '江蘇省'
    when '33' then '浙江省'
    when '34' then '安徽省'
    when '35' then '福建省'
    when '36' then '江西省'
    when '37' then '山東省'
    when '41' then '河南省'
    when '42' then '湖北省'
    when '43' then '湖南省'
    when '44' then '廣東省'
    when '45' then '廣西壯族自治區'
    when '46' then '海南省'
    when '50' then '重慶市'
    when '51' then '四川省'
    when '52' then '貴州省'
    when '53' then '云南省'
    when '54' then '西藏自治區'
    when '61' then '陜西省'
    when '62' then '甘肅省'
    when '63' then '青海省'
    when '64' then '寧夏回族自治區'
    when '65' then '新疆維吾爾自治區'
    when '71' then '臺灣省'
    when '81' then '香港特別行政區'
    when '82' then '澳門特別行政區'
    else '未知'??? ?
    end?? as 省份 ,
    year(curdate())-if(length(member_idcard)=18,substring(member_idcard,7,4),if(length(member_idcard)=15,concat('19',substring(member_idcard,7,2)),null)) as 年齡,
    case if(length(member_idcard)=18, cast(substring(member_idcard,17,1) as UNSIGNED)%2, if(length(member_idcard)=15,cast(substring(member_idcard,15,1) as UNSIGNED)%2,3))
    when 1 then '男'
    when 0 then '女'
    else '未知'
    end as 性別
    FROM member




    -------未完,待續!



















    ----

    總結

    以上是生活随笔為你收集整理的mysql常用语句整理的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。