好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Mysql常用運算符與函數匯總

Mysql常用運算符與函數匯總

熱門標簽:電銷機器人價格多少錢一臺 怎么辦理400電話呢 電話機器人免費嗎 400電話申請什么好 怎么申請400電話申請 好搜地圖標注 地圖標注圖標素材入駐 百度地圖標注地方備注 龍圖酒吧地圖標注

我們先把數據表建好

use test;
create table `employee`(
 emp_no int unsigned,
 emp_name varchar(30),
 emp_sex varchar(3),
 emp_age tinyint unsigned,
 sal double,
 history datetime
);
insert into employee values(1, '張三', '男', 18, 5000, '2012-04-23'),
(2, '李四', '男', 27, 4500, '2013-05-23'),
(3, '王五', '男', 23, 4700, '2012-04-21'),
(4, '子龍', '男', 19, 3800, '2011-03-04'),
(5, '李白', '男', 15, 6200, '2015-09-09'),
(6, '劉備', '男', 28, 2500, '2016-02-11'),
(7, '呂布', '男', 21, 6000, '2010-10-18'),
(8, '尚香', '女', 16, 4500, '2011-09-26'),
(9, '小喬', '女', 15, null, '2013-07-05'),
(10, '大喬', '女', 16, 5000, '2017-09-01');

常用的運算符:
1: 等于( = )

 select * from employee where sal = 3800;
 select * from employee where sal = null;  --這里查詢不到為null的數據

2: 等于( => )

 select * from employee where sal => 3800;
 select * from employee where sal => null; --這里可以查詢到為null的數據

3: is判斷(null)

 select * from employee where sal is null;
 select * from employee where sal is not null;

4: null值判斷還可以使用isnull();

 select * from employee where isnull(sal);
 select * from employee where !isnull(sal);

5: 在區間(between)內  between min and max  ps:這里是一個閉區間

    select * from employee where sal between 4500 and 5000;

6: 不在區間內

    select * from employee where sal not between 4500 and 5000;  --null不為包括進去

7: and 和 or

 select * from employee where sal not between 4500 and 5000 or sal is null;
 select * from employee where sal = 4500 and emp_sex = '女';

8: 小于(), 大于(>), 小于等于(=), 大于等于(>=)

    select * from employee where sal >= 4500;

***************************************************************************************************************

數學函數
1: rand();

 select rand() from dual; --dual是一個偽表
 select 1+1 from dual;
 select rand(); --可以簡寫

2: least(value1, value2, ...) 返回最小值

 select least(54,76,4,65,76,87,87,56,65,654,45,23,1,76);
 select least(54,76,4,65,76,87,87,56,65,654,45,23,1,76) as min_value; --列名可以起一個別名

3: greatest(value1, value2, ...) 返回最大值

    select greatest(54,76,4,65,76,87,87,56,65,654,45,23,1,76);

4: round(M, D); 返回M的四舍五入的值, D表示要保留幾們小數,默認值是0

 select round(1.69);
 select round(1.69, 1);

5: abs() 絕對值

 select 5-10;
 select abs(5-10);

***************************************************************************************************************

匯總函數

1: avg(); 

 select * from employee where sal >= 6000;
 select avg(sal) from employee where sal >= 6000;

2: count()

 select count(*) from employee;
 select count(emp_name) from employee;
 select count(sal) from employee;  --打印9 這里會忽略null值
 select count(*) from employee where sal >= 4000;
 select count(*) from employee where sal = 4000 or sal is null;

3: sum()

    select sum(sal) from employee where sal >= 6000;

4: min()

    select min(sal) from employee;

5: max()

    select max(sal) from employee;

***************************************************************************************************************

日期函數

1: 獲取當前的日期時間

 select now(), sysdate(), current_timestamp();
 select now(6), sysdate(6), current_timestamp(6);
 ps: now(), current_timestamp();沒有區別, 表示sql開始執行時的時間
  sysdate()表示這個函數開始時間

2: 獲取當前日期

    select curdate();   --只有年月日

3: 獲取當前時間

    select curtime();   --只有時分秒

4: 日期的加運算date_add     

 select history, date_add(history, interval '1 12:10' day_minute) from employee; --date_add(history, interval '1 12:10' day_minute)
 select history, date_add(history, interval '1-1' year_month) from employee;  --date_add(history, interval '1-1' year_month)
 select history, date_add(history, interval '1' second) from employee;    --date_add(history, interval '1' second)

5: 日期的減運算data_sub

    select history, date_sub(history, interval '1-1' year_month) from employee; 

6: 計算日期差

    select history, sysdate(), datediff(sysdate(), history) from employee;     --以天數來表示

7: 獲取日期的指定部分(把日期轉換為指定的格式)  date_format()

 select history, date_format(history, '%Y年%m月%d號') from employee;
 select history, date_format(history, '%d號') from employee;
 select history, date_format(history, '%Y年%m月%d號 %H時%i分%s秒') from employee;

8: 計算出一個日期是星期幾

    select history, dayname(history) from employee;

9: 中文日期字符串轉換日期str_to_date()
 

 insert into employee values(11, '張飛', '男', 22, 3000, '2017年02月01號'); --報錯
 insert into employee values(11, '張飛', '男', 22, 3000, str_to_date('2017年02月01號', '%Y年%m月%d號 %H時%i分%s秒'));

    insert into employee values(12, '二哥', '男', 22, 3000, str_to_date('2017年02月01號 23時02分02秒', '%Y年%m月%d號 %H時%i分%s秒'));
    insert into employee values(12, '二哥', '男', 22, 3000, str_to_date('2017年02月01號 11時02分02秒', '%Y年%m月%d號 %h時%i分%s秒'));
    ps: 如果是h則表示12小制, 如果是大H則表示24小明制;

字符串函數

1: left(str, len) 返回字符串str的左端len個字符

    select left('abcdefg', 5);
 

2: length()

    select length('abcdefg');

3: lower(str) 返回小寫的字符串str

    select lower('HELLO');

4: substring() 取子字符串, 第二個參數是截取的起始位置, 第三個參數是要截取的長度

    select substring('helloworld',2,3);

5: concat() 字符串拼接

    select concat(emp_name, '員工') from employee;

6: replace(替換

    select replace(emp_name, '李', '老') from employee where emp_name = '李四';

您可能感興趣的文章:
  • mysql常用函數實例總結【聚集函數、字符串、數值、時間日期處理等】
  • MySQL常用類型轉換函數總結(推薦)
  • Mysql常用函數大全(分類匯總講解)
  • mysql中常用日期比較與計算函數
  • MySQL中的常用函數
  • mysql常用日期時間/數值函數詳解(必看)
  • MySQL常用時間函數詳解(推薦)
  • MySQL常用聚合函數詳解
  • mysql常用函數匯總(分享)
  • mysql截取函數常用方法使用說明
  • MySQL 常用函數總結

標簽:廣西 內江 汕尾 撫順 溫州 防疫工作 固原 浙江

巨人網絡通訊聲明:本文標題《Mysql常用運算符與函數匯總》,本文關鍵詞  Mysql,常用,運算符,與,函數,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Mysql常用運算符與函數匯總》相關的同類信息!
  • 本頁收集關于Mysql常用運算符與函數匯總的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 亚洲色婷婷久久精品AV蜜桃久久| 精品欧美高清一区二区免费| 黄色大片网| sao浪双xing挨cao记by张嘴吃肉 | 中国曰批片| 国产成人精品免费| 伴郎强上准新娘| 精品一级A片一区二区免费视频 | 黄网视频在线观看| 色网免费观看| 印度学生xxxxx性14一16| 国产成人精品午夜| 95国产成人精品视频久爱成疾| 激情 小说 亚洲 图片 伦| 国模午晴大胆私拍炮战| voyeur 中国女厕 亚洲女厕| 日韩高清一区| 成年女人视频免费观看一| 日本一级理论片在线大全| 秀婷程仪公欲息肉婷在线观看| 添奶头舔到高潮奶水会喷出来| 欧洲xxxxxxxxx69| 果冻传媒新剧国产完整版在线| 禁漫?天堂?H漫画网站| 欧美大尺度毛片9| 国精产品一区一区三区公司| 涩涩视频在线看| 女人的逼网站| 韩国黄色小说| 国产精品44p| 久久久久精品国产免费看 | 日本xxxxhd18日本| 日本电车痴汉视频| chinese男校草飞机videos| 日韩天天摸天天澡天天爽视频| 91啪亚洲精品久久久久| 精品人妻无码一区二区出白浆潮喷| 糖心Vlog破解免费版| 美女被日的视频| 男生女生插插| 用力插深点|