MYSQL題目練習以及profile

2022-09-08 20:09:14 字數 2937 閱讀 6399

題1:

建立乙個儲存引擎為innodb ,字符集為gbk的表test ,欄位為id和namevarchar(16),並檢視表結構完成下列要求:

①插入一條資料:1,newlhr。

②批量插入資料:2,小麥苗;3,ximaimiao。要求中文不能亂碼。

③首先查詢名字為newlhr的記錄,然後查詢id大於1的記錄。

④把資料id等於1的名字newlhr更改為oldlhr。

⑤在字段name前插入age欄位,型別為tinyint(4)。

答案:

```sql

#1create table test (

id int ( 4 ) not null,

name varchar ( 20 ) not null

) engine = innodb default charset = gbk;

#2insert into test(id,name) values(1,"newhr");

#3insert into test values(2,"小麥"),(3,"xiaomai");

#4 update test set name="oldhr" where id = 1;

#5 alter table test add age tinyint(4) after id;

題2:

有如下表結構,其中,name欄位代表「姓名」,score欄位代表「分數」。

);1)查詢單分數最高的人和單分數最低的人。

2)查詢兩門分數加起來的第2~5名。

3)查詢兩門總分數在150分以下的人。

4)查詢兩門平均分數介於60和80的人。

5)查詢總分大於150分,平均分小於90分的人數。

6)查詢總分大於150分,平均分小於90分的人數有幾個。

select

*from t1 where score in

(select

max(score)

from t1 union

allselect

min(score)

from t1)

;select name,

sum(score)

from t1 group

by name order

bysum

(score)

desc

limit1,

4;select name,

sum(score)

from t1 group

by name h**ing

sum(score)

<

150;

select name,

**g(score)

from t1 group

by name h**ing

**g(score)

between

60and80;

select name ,

**g(score)

,sum

(score)

from t1 group

by name h**ing

**g(score)

<

90and

sum(score)

>

150;

select

count

(name)

from t1 group

by name h**ing

**g(score)

<

90and

sum(score)

>

150;

mysql中的ifnull()有什麼作用?

使用ifnull()方法能使mysql中的查詢更加精確。ifnull()方法將會測試它的第乙個引數,若不為null,則返回該引數的值,否則返回第二個引數的值.

profile的意義及使用場景

mysql可以使用profile分析sql語句的效能消耗情況。例如,查詢到sql會執行多少時間,並看出cpu、記憶體使用量,執行過程中系統鎖及表鎖的花費時間等資訊。

通過h**e_profiling引數可以檢視mysql是否支援profile,通過profiling引數可以檢視當前系統profile是否開啟:

show variable like 「%profil%」

以下是有關profile的一些常用命令。

●set profiling=1;:基於會話級別開啟,關閉則用set profiling=off。

●show profile cpu for query 1;:檢視cpu的消耗情況。

●show profile memory for query 1;:檢視記憶體消耗情況。

●show profile block io,cpu for query 1;:檢視i/o及cpu的消耗情況。

mysql中的prof是什麼意思 MySQL索引

索引的種類 普通索引 最基本的索引,沒有任何限制。唯一索引 索引列的值必須唯一,但允許有空值。如果是組合索引,則列值的組合必須唯一。主鍵索引 是一種特殊的唯一索引,乙個表只能有乙個主鍵,不允許有空值。建立主鍵時就自動生成了該索引。組合索引 指多個欄位上建立的索引,只有在查詢條件中使用了建立索引時的第...

題目篇 MySQL練習題 一

1 查詢最晚入職員工的所有資訊,為了減輕入門難度,目前所有的資料裡員工入職的日期都不是同一天 sqlite裡面的注釋為 mysql為comment 表的建立如下 create table employees emp no int 11 notnull 員工編號 birth date date not...

kd tree 題目練習

kd tree原理詳解 kd 樹介紹 模板和部分題借鑑 kd tree小結 例題一 p4475 巧克力王國 思路 根據巧克力a和可可b建立kd tree,每個節點維護子樹的最大的x,y以及最小的x,y,乙個子樹的權值和sum,每次查詢,如果四對極值點 x y滿足 x a y b includeusi...