mysql普通語句

2021-09-25 15:37:59 字數 2327 閱讀 7608

需求:查詢最大值

select max(time) from table;
需求:一條mysql語句查詢出男女的人數

select count(case when mz ='漢族' then mz end) as h,count(case when mz ='維吾爾族' then mz end) as w from tb_r_jbxx where addressid ='652901101204';
需求:mysql中將多行資料合併成一行資料

select am.activeid,group_concat(m.modelname separator ',') modelname

from activemodel am

join model m

on am.modelid=m.modelid

where m.valid=1

group by am.activeid

需求:union all

(select aid,title from article) 

union all

(select bid,title from blog)

limit 2

需求:time和datetime

datetime  yyyy-mm-dd hh:mm:ss

time hh:mm:ss

需求:獲取某年某月某日的資料

select * from `user` where date_format(birthday,'%y-%m-%d')='2017-07-07';
需求:獲取當月多少天

dayofmonth(last_day('20$-10-01'))
需求:資料排序 asc、desc

指定按照薪水由大到小排序(降序關鍵字desc)

指定按照薪水由小到大排序(公升序關鍵字 asc)

需求:查詢資料=>時間範圍的條件

在這裡插入**片
需求:合併兩個查詢記錄

select column_name(s) from table_name1     |     select column_name(s) from table_name1

union | union all

select column_name(s) from table_name2; | select column_name(s) from table_name2;

1、select語句列的數量、順序必須相同,列的型別也要求相似;

2、union和union all結果集中的列名總是等於第乙個select語句中的列名稱相同。

union 去除重複行,union all 不去除

需求:插入多個記錄

insert into persons 

(id_p, lastname , firstname, city )

values

(200,'haha' , 'deng' , 'shenzhen'),

(201,'haha2' , 'deng' , 'gd'),

(202,'haha3' , 'deng' , 'beijing');

delete from table_name [where clause]

delete from maintain_archive where id = #

insert into table_name ( field1, field2,...fieldn )

values

( value1, value2,...valuen );

update table_name set field1=new-value1, field2=new-value2

[where clause]

update table_name set field1=new-value1, field2=new-value2

where id = #

select column_name,column_name

from table_name

[where clause]

[limit n][ offset m]

mysql普通日誌相關查詢語句

記錄了伺服器接收到的每乙個查詢或是命令,無論這些查詢或是命令是否正確甚至是否包含語法錯誤,general log 都會將其記錄下來 記錄的格式為 也正因為mysql伺服器需要不斷地記錄日誌,開啟general log會產生不小的系統開銷。因此,mysql預設是把general log關閉的。檢視日誌...

mysql支援語句 mysql語句

delete 刪除資料表中的行 可以刪除某一行,也可以在不刪除資料表的情況下刪除所有行 刪除某一行 delete from 資料表名稱 where 列名稱 值 刪除所有行 delete from 資料表名稱 drop 刪除資料表或資料庫,或刪除資料表字段。刪除資料庫 drop database 資料...

常用mysql語句 常用MySql語句

新建資料表 drop table if exists ga game way create table ga game way id int 11 unsigned not null auto increment comment id primary key id using btree,主鍵 un...