MySQL 常用查詢

2021-09-26 13:25:30 字數 1278 閱讀 1589

1、

select uuid();

select now();

set @schoolid = '1234567890123456789';

select * sys_user_info where mobile is null

select * sys_user_info where mobile is not null

set @adminid = '';

select @adminid := id from sys_user_info where mobile = 'admin';

-- 時間格式化

select date_format(capture_time, '%y-%m-%d'),`inout`,student_id

from trans_student_inout

where date_format(created_time, '%y-%m-%d')='2019-08-01';

group by date_format(capture_time, '%y-%m-%d'),`inout`,student_id;

-- 時間格式化

select * from sys_user_info where date_format(created_time, '%y-%m-%d') = '2019-08-01';

2、concat 函式

函式:concat(str1,str2,…)

描述:字串 s1,s2 等多個字串合併為乙個字串;合併多個字串;

注意:如有任何乙個引數為null ,則返回值為 null;

例項

select concat("sql ", "runoob ", "gooogle ", "facebook") as concatenatedstring;
例項

set @ex123 = '\'123',\'456\'';

set @sql123 = concat('select * from sys_user_info where user_name in (',@ex123,')');

select @sql123;

4、

5、6、

7、8、

9、0、

mysql 查詢 常用 mysql常用查詢

一.group concat函式,以指定的分割符合並列,與group by 一起用 例 selectgroup concat c.columnname separator group by 二.preparedstatement.return generated keys 得到剛剛插入記錄的id p...

mysql常用的查詢 MySQL常用查詢

資料庫 1.查詢所有資料的大小 data length 資料大小 index length 索引大小 select concat round sum data length index length 1024 1024,2 mb as data from information schema.tab...

mysql常用的查詢 MySQL常用查詢

select from unixtime create time,y m as time,sum sales amount sales amount sum from sales group by time 執行結果如下 查詢每年的銷售額 select from unixtime create ti...