mysql 樓層 mysql語法

2021-10-17 16:46:22 字數 3200 閱讀 9420

1.時間類的語法

//這裡是將日期格式化 ,其作用可以按這個時間分組。從而統計每天的資訊

date_format(t1.end_time,'%y-%m-%d %h:%i:%s') days,

2.將字串型別結果轉為數值型

//mysql查詢結果 字串轉int select 欄位+0 例如

select max(menu_id+0) mid from sys_menu

3.如果為空則用其他值代替

//如果為空的時候就用1代替

ifnull(t1.starte,'1') `starte`,

4.mysql中如果使用到關鍵字報錯;可以加上 `` 這個符號,這不是單引號。是鍵盤左上角數字鍵1前面的那個符號

//大於符號案例

and t1.entry_time >=#//小於符號案例

and t1.entry_time <=#

6.將內容整合在一起的語法。用於模糊查詢

//將兩邊的值合併在一起

and t1.name like concat('%',#,'%')

7.mysql  新增表注釋

alter table test1 comment '修改後的表的注釋';

8.mysql  新增字段注釋

alter table tb_coupon_pool modify column `id` varchar(32) not null comment '主鍵id';

//注意字段原有的型別加上

9.mysql  查詢判空

and t1.positive_ocde_url is notnull

and t1.positive_ocde_url isnull

10.查詢結果整合到一起(缺省會以逗號分隔)(預設限制結果長度1024,太長會丟失資料)

select t1.id , group_concat(t1.id) marks

from tb_driver t1

group by t1.id

11、根據時間查詢案例(處理起始時間和結束時間為同一天查詢為空的問題)

and t1.create_time<=concat('','$',' 23:59:59')

12.獲取最小值、最大值,進行分組

select min(t1.money) money fromtb_shifts t1where t1.lineid =# group by t1.type

13 mysql運算保留兩位小數

format(sum(t1.platmoney/100),2) platmoney,

15、 mysql設定時間預設值

設定資料建立時間預設值,mysql會自動填充當前時間,不用**處理

current_timestamp

資料最後修改時間、勾選    根據當前時間戳更新即可,mysql會在資料修改時根據當前時間修改

16、合併結果、合併多張表的結果

17   if用法

select

id ,if(phone ='' , 'a',phone) b

from sys_admin

條件成立顯示前面代替的字串,條件不成立 ,顯示後面的

18、刪除字段

alter table tb_quality_inspect_day drop content;

19、刪除記錄、刪除資料

delete from tb_quality_inspect_day where is_deleted !='0'

20、修改欄位名、修改字段型別、修改字段注釋

alter table tb_quality_inspect_day change floor_num floor_num varchar(50) comment "樓層";

21、新增字段語法

alter table tb_job add column `is_deleted` varchar(11) character set utf8 collate utf8_bin default '0' comment '是否刪除(0、正常;其他、刪除)';

alter table tb_job add column `created_id` varchar(32) character set utf8 collate utf8_bin default null comment '建立人id';

alter table tb_job add column `create_time` datetime default current_timestamp(0) comment '建立時間';

alter table tb_job add column `last_update_time` datetime default current_timestamp(0) on update current_timestamp(0) comment '最後修改時間';

alter table tb_job add column `last_update_id` varchar(32) character set utf8 collate utf8_bin default null comment '最後修改人id';

22、修改表名

rename table bim_question_log to tb_bim_question_log;

23、mysql獲取表字段名稱、獲取字段注釋、獲取資料庫字段型別

select table_name, column_name dbname, data_type dbtype, column_comment label from information_schema.columns where table_name=表名and table_schema =資料庫名稱

24、更改性別面試題sql、修改性別面試題sql

update test02set ***=if(***='1','2','1');

mysql 語法 mysql的刪除語法

刪除資料庫 drop database test 刪除表 drop table ifexists test 刪除表資料 delete from test where id 1 不會減少表或索引所占用的空,可以加where條件,可以進行rollback回滾 truncate table test 執行...

mysql 語法入門 mysql基礎語法

1 dml 增刪改查 1 select 獲取資料 select from 表名 where 條件 2 update 更新資料 update 表名 set 欄位名 值,欄位名 值 where 條件 3 delete 刪除資料 delete from 表名 where 條件 4 insert into ...

mysql語法例項 mysql 儲存過程語法及例項

1 下面為乙個儲存過程的定義過程 create procedure proc name in parameter integer begin declare variable varchar 20 if parameter 1 then set variable mysql else set var...