国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

Mysql常用運算符與函數匯總

2024-07-24 12:51:10
字體:
來源:轉載
供稿:網友

我們先把數據表建好

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 格尔木市| 阳泉市| 绍兴市| 卢龙县| 天水市| 隆安县| 衡阳县| 运城市| 九寨沟县| 富蕴县| 福安市| 莆田市| 东城区| 瑞安市| 治县。| 信宜市| 高清| 通海县| 泰兴市| 泊头市| 富阳市| 新密市| 通道| 吐鲁番市| 集安市| 寿宁县| 竹山县| 赤水市| 五莲县| 吴忠市| 彩票| 宜君县| 罗平县| 成武县| 蓬安县| 台东市| 博乐市| 张北县| 沿河| 桃江县| 额济纳旗|