1. 程式人生 > 實用技巧 >如何設定在word中開啟MathType的快捷鍵

如何設定在word中開啟MathType的快捷鍵

單表查詢

簡單查詢

- 建立表
DROP TABLE IF EXISTS `person`;
CREATE TABLE `person` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `age` tinyint(4) DEFAULT '0',
  `sex` enum('','','人妖') NOT NULL DEFAULT '人妖',
  `salary` decimal(10,2) NOT NULL DEFAULT '250.00',
  `hire_date` date NOT NULL,
  `dept_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;

-- 建立資料

-- 教學部
INSERT INTO `person` VALUES ('1', 'alex', '28', '人妖', '53000.00', '2010-06-21', '1');
INSERT INTO `person` VALUES ('2', 'wupeiqi', '23', '', '8000.00', '2011-02-21', '1');
INSERT INTO `person` VALUES ('3', 'egon', '30', '', '6500.00', '2015-06-21', '1');
INSERT INTO `person` VALUES ('4', 'jingnvshen', '18', '', '6680.00', '2014-06-21', '1');

-- 銷售部
INSERT INTO `person` VALUES ('5', '歪歪', '20', '', '3000.00', '2015-02-21', '2');
INSERT INTO `person` VALUES ('6', '星星', '20', '', '2000.00', '2018-01-30', '2');
INSERT INTO `person` VALUES ('7', '格格', '20', '', '2000.00', '2018-02-27', '2');
INSERT INTO `person` VALUES ('8', '週週', '20', '', '2000.00', '2015-06-21', '2');

-- 市場部
INSERT INTO `person` VALUES ('9', '月月', '21', '', '4000.00', '2014-07-21', '3');
INSERT INTO `person` VALUES ('10', '安琪', '22', '', '4000.00', '2015-07-15', '3');

-- 人事部
INSERT INTO `person` VALUES ('11', '周明月', '17', '', '5000.00', '2014-06-21', '4');
-- 鼓勵部
INSERT INTO `person` VALUES ('12', '蒼老師', '33', '', '1000000.00', '2018-02-21', null);

#查詢語法: 
select [distinct]*(所有)|欄位名,...欄位名 from 表名;
 
#查詢所有欄位資訊
select * from person;
 
#查詢指定欄位資訊
select id,name,age,sex,salary from person;
 
#別名查詢,使用的as關鍵字,as可以省略的
select name,age as'年齡',salary '工資' from person;
 
#直接對列進行運算,查詢出所有人工資,並每人增加100塊.
select (5/2);
select name, salary+100 from person;
 
#剔除重複查詢
select distinct age from person;

條件查詢

條件查詢:使用WHERE關鍵字 對簡單查詢的結果集 進行過濾

  1.比較運算子: > < >= <= = <>(!=)

  2. null 關鍵字:is null , not null

  3.邏輯運算子: 與 and 或 or (多個條件時,需要使用邏輯運算子進行連線)

#查詢格式:
select [distinct]*(所有)|欄位名,...欄位名 from 表名 [where 條件過濾]
 
#比較運算子: > < >= <= = <>(!=)    is null 是否為null
select * from person where age = 23;
select * from person where age <> 23;
select * from person where age is null;
select * from person where age is not null;
 
#邏輯運算子: 與 and 或 or
select * from person where age = 23 and salary =29000;
select * from person where age = 23 or salary =29000;

區間查詢

關鍵字between10and20 :表示 獲得10 到 20 區間的內容

# 使用  between...and  進行區間 查詢
select * from person where salary between 4000 and 8000;
ps: between...and 前後包含所指定的值
等價於 select * from person where salary >= 4000 and salary <= 8000;

集合查詢

關鍵字:in, not null

#使用 in 集合(多個欄位)查詢
select * from person where age in(23,32,18);
等價於: select * from person where  age =23 or age = 32 or age =18;
 
#使用 in 集合 排除指定值查詢
select * from person where age not in(23,32,18);

模糊查詢

關鍵字like , not like

    %: 任意多個字元

    _ : 只能是單個字元

#模糊查詢  like %:任意多個字元,  _:單個字元
 
#查詢姓名以""字開頭的
select * from person where name like '張%';
#查詢姓名以""字結尾的
select * from person where name like '%張';
#查詢姓名中含有""字的
select * from person where name like '%張%';
 
#查詢 name 名稱 是四個字元的人
select * from person where name like '____';
#查詢 name 名稱 的第二個字元是 'l'的人
select * from person where name like '_l%';
 
#排除名字帶 a的學生
select * from student where name not like 'a%'

排序查詢

關鍵字:ORDER BY 欄位1DESC, 欄位2ASC

#排序查詢格式:
select 欄位|* from 表名 [where 條件過濾] [order by 欄位[ASC][DESC]]
 
升序:ASC 預設為升序
降序:DESC
PS:排序order by 要寫在select語句末尾
 
#按人員工資正序排列,注意:此處可以省略 ASC關鍵字
select * from person order by salary ASC;
select * from person order by salary;
 
#工資大於5000的人,按工資倒序排列
select * from person where salary >5000 order by salary DESC;
 
#按中文排序
select * from person order by name;
 
#強制中文排序
select * from person order by CONVERT(name USING gbk);
ps:UTF8 預設校對集是 utf8_general_ci , 它不是按照中文來的。你需要強制讓MySQL按中文來排序
 

聚合查詢

聚合: 將分散的聚集到一起.

聚合函式: 對列進行操作,返回的結果是一個單一的值,除了 COUNT 以外,都會忽略空值

COUNT:統計指定列不為NULL的記錄行數;

SUM:計算指定列的數值和,如果指定列型別不是數值型別,那麼計算結果為0;

MAX:計算指定列的最大值,如果指定列是字串型別,那麼使用字串排序運算;

MIN:計算指定列的最小值,如果指定列是字串型別,那麼使用字串排序運算;

AVG:計算指定列的平均值,如果指定列型別不是數值型別,那麼計算結果為0;

#格式:
select 聚合函式(欄位) from 表名;
 
#統計人員中最大年齡、最小年齡,平均年齡分別是多少
select max(age),min(age),avg(age) from person;

分組查詢

分組的含義:將一些具有相同特徵的資料 進行歸類.比如:性別,部門,崗位等等

怎麼區分什麼時候需要分組呢?

  套路: 遇到 "每" 字,一般需要進行分組操作.

  例如: 1. 公司每個部門有多少人.

     2. 公司中有 多少男員工 和 多少女員工.

#分組查詢格式:
select 被分組的欄位 from 表名 group by 分組欄位 [having 條件欄位]
ps: 分組查詢可以與 聚合函式 組合使用.

#查詢每個部門的平均薪資
select avg(salary),dept from person  GROUP BY dept;

#查詢每個部門的平均薪資 並且看看這個部門的員工都有誰?
select avg(salary),dept,GROUP_CONCAT(name) from person GROUP BY dept;
#GROUP_CONCAT(expr):按照分組,將expr字串按逗號分隔,組合起來

#查詢平均薪資大於10000的部門, 並且看看這個部門的員工都有誰?  
select avg(salary),dept,GROUP_CONCAT(name) from person GROUP BY dept; having avg(salary)>10000;

where 與 having區別:
#執行優先順序從高到低:where > group by > having
#1. Where 發生在分組group by之前,因而Where中可以有任意欄位,但是絕對不能使用聚合函式。
#2. Having發生在分組group by之後,因而Having中可以使用分組的欄位,無法直接取到其他欄位,可以使用聚合函式

分頁查詢

好處:限制查詢資料條數,提高查詢效率

#查詢前5條資料
select * from person limit 5;
 
#查詢第5條到第10條資料
select * from person limit 5,5;
 
#查詢第10條到第15條資料
select * from person limit 10,5;
 
ps: limit (起始條數),(查詢多少條數);

正則表示式

MySQL中使用 REGEXP 操作符來進行正則表示式匹配。

模式描述
^ 匹配輸入字串的開始位置。
$ 匹配輸入字串的結束位置。
. 匹配任何字元(包括回車和新行)
[...] 字元集合。匹配所包含的任意一個字元。例如, '[abc]' 可以匹配 "plain" 中的 'a'。
[^...] 負值字元集合。匹配未包含的任意字元。例如, '[^abc]' 可以匹配 "plain" 中的'p'。
p1|p2|p3 匹配 p1 或 p2 或 p3。例如,'z|food' 能匹配 "z" 或 "food"。'(z|f)ood' 則匹配 "zood" 或 "food"。

# ^  匹配 name 名稱 以 "e" 開頭的資料
select * from person where name REGEXP '^e';
 
# $  匹配 name 名稱 以 "n" 結尾的資料
select * from person where name REGEXP 'n$';
 
# . 匹配 name 名稱 第二位後包含"x"的人員 "."表示任意字元
select * from person where name REGEXP '.x';
 
# [abci] 匹配 name 名稱中含有指定集合內容的人員
select * from person where name REGEXP '[abci]';
 
# [^alex] 匹配 不符合集合中條件的內容 , ^表示取反
select * from person where name REGEXP '[^alex]';
#注意1:^只有在[]內才是取反的意思,在別的地方都是表示開始處匹配
#注意2 : 簡單理解 name  REGEXP '[^alex]' 等價於 name != 'alex'
 
# 'a|x' 匹配 條件中的任意值
select * from person where name REGEXP 'a|x';  
 
#查詢以w開頭以i結尾的資料
select * from person where name regexp '^w.*i$';
#注意:^w 表示w開頭, .*表示中間可以有任意多個字元, i$表示以 i結尾

正則詳情參考:http://www.cnblogs.com/wangfengming/articles/8067037.html

SQL語句關鍵字執行順序

查詢:姓名不同人員的最高工資,並且要求大於5000元,同時按最大工資進行排序並取出前5條.

select name, max(salary)
   
from person  
   
where name is not null  
   
group by name  
   
having max(salary) > 5000
   
order by max(salary)
 
limit 0,5

SQL 語句的執行順序如下:

   (1). 首先執行 FROM 子句, 從 person 表 組裝資料來源的資料

   (2). 執行 WHERE 子句, 篩選 person 表中 name 不為 NULL 的資料

   (3). 執行 GROUP BY 子句, 把 person 表按 "name" 列進行分組

   (4). 計算 max() 聚集函式, 按 "工資" 求出工資中最大的一些數值

   (5). 執行 HAVING 子句, 篩選工資大於 5000的人員.

   (7). 執行 ORDER BY 子句, 把最後的結果按 "Max 工資" 進行排序.

   (8). 最後執行 LIMIT 子句, . 進行分頁查詢

執行順序: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY ->limit 

————————————————————————————————————

來自於轉載:https://www.cnblogs.com/bypp/p/8617944.html