sql一些簡單的查詢語句

2021-09-09 09:06:22 字數 840 閱讀 6504

1.查詢今天的資料

select * from 函式名(字段,getdate())

2.查詢昨天的資料

select * from 函式名(字段,dateadd(day,-1,getdate()))

3.查詢前天的資料

select * from 函式名(字段,dateadd(day,-2,getdate()))

4.查詢本月的資料

declare @date date set  @date=getdate() select * from 函式名(字段,year(@date),datepart(month,@date))

5.查詢上月的資料

declare @date date,@year int,@month int

set  @date=getdate() select @year=year(@date),@month=month(@date)

select * from 函式名(字段,case when @month=1 then @year-1 else @year end,case when @month=1 then 12 else @month-1 end)

6.查詢今年的資料

select * from 函式名(字段,datepart(year,getdate()))

7.查詢去年的資料

select * from 函式名(字段,datepart(year,getdate())-1)

一些常用的SQL查詢語句

select alter table case when o.schema id is notnull then select name from sys.schemas where schema id o.schema id else end object name parent object i...

一些簡單的SQL語句結構

筆試裡除了複雜一些的select語句,也會有一些update等語句,從w3school看了一下,總結一下 insert語句 語法 insert into table name 列1,列2,values 值1,值2,例項 insert into persons lastname,address val...

一些sql語句

一。在oracle中建表,怎麼實現id自動編號 1 建表 create table code test id int,name varchar2 20 2.建立序列 create sequence s country id increment by 1 start with 1 maxvalue 9...