工作中的sql語句總結

2022-03-20 11:13:06 字數 936 閱讀 5317

1,查詢mysql 資料庫 自動 新增 序號 欄位列1,2,3,4

1' ) a,(select @rowno :=0) b

2,mysql的分頁語句

limit後面第乙個引數是index,從0開始;第二個引數是pagesize

string sql = string.format("

",gridprop.filterstring,(gridprop.selectpage-1)* gridprop.pagesize,gridprop.pagesize);

上面是轉為c#, selectpage在前台設定,從1開始。

3,查詢

今天select * from 表名 where to_days(時間欄位名) = to_days(now());

昨天select * from 表名 where to_days( now( ) ) - to_days( 時間欄位名) <= 1

7天select * from 表名 where date_sub(curdate(), interval 7 day) <= date(時間欄位名)

近30天

select * from 表名 where date_sub(curdate(), interval 30 day) <= date(時間欄位名)

本月select * from 表名 where date_format( 時間欄位名, '%y%m' ) = date_format( curdate( ) , '%y%m' )

上一月select * from 表名 where period_diff( date_format( now( ) , '%y%m' ) , date_format( 時間欄位名, '%y%m' ) ) =1

4, 將表b中的字段插入到表a中。

insert into a (id) select id from b

最近工作中遇到的SQL語句

1.求表中某列的和,並把其值賦給乙個變數 sqlcommand cmd new sqlcommand select sum aa from table conn int32 aa int32 cmd.executescalar 2.判斷欄位的值是否為數字 select from hr user wh...

工作中的sql

isnull like top order by desc convert substring as 工作中的例子 1.select top 1 convert float,isnull gryjce,0.001 2 as gryjce from vet gryjce zgzt where kh c...

工作中常用SQL語句

新增列 執行下列命令,列會預設新增到表字段末尾 alter table 表名 add column 列名 varchar 30 如果想指定字段位置,可以使用mysql提供的first 設定為第一列 和after 設定位於某個字段之後 first和 after關鍵字只用於 add 子句 刪除列 alt...