sql資料庫查詢日期
Ⅰ sql獲取當前年月日
1、首先直接使用getdate就可以獲得當天的日期。
Ⅱ 資料庫的日期區間查詢方法。
access中有個mid函數,可以用來截取字元串或者日期。
select * from 表名 where mid([TestTime],5,10) ='04/19/2013'其中,5代表截取的開始位置,從左數,10代表截取的長度。
資料庫的日期區間查詢有兩種情況:
1:查詢給定時間在開始時間列與結束時間列范圍中數據;
2:查詢日期列在開始時間列與結束時間列范圍中數據。
第一種:<,>, <= , >=
select * from 表名 where 日期列 >= to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss')
and t.日期列 <= to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')。
第二種 between and
select * from 表名 where 日期列 between to_date('2015-10-20 00:00:00','yyyy-mm-dd
hh24:mi:ss')and to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')。
(2)sql資料庫查詢日期擴展閱讀:
SQL資料庫語句:
創建資料庫:
CREATE DATABASE database-name。
刪除資料庫:
drop database dbname。
創建新表:
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)。
刪除新表:
drop table tabname。
增加一個列:
Alter table tabname add column col type。
添加主鍵:
Alter table tabname add primary key(col)。
刪除主鍵:
Alter table tabname drop primary key(col)。
創建索引:
create [unique] index idxname on tabname(col?.)。
刪除索引:
drop index idxname。
創建視圖:
create view viewname as select statement。
刪除視圖:
drop view viewname。
參考資料來源:網路-sql語句大全
Ⅲ SQL資料庫中的是年月日時分秒格式的,什麼語句能實現年月日的查詢
1、SEELCT *from表名where日期='年月日'
2、查詢:
declare @date varchar(20)
set @date = '2013-06-06 13:30:25' +'%'
SELECT *FROMTELEPHONE_HISTORYWHERECONVERT(VARCHAR(20) ,RECVTIME, 120)
LIKE @date
其中:CONVERT(VARCHAR(20) ,RECVTIME, 120) 就是將日期 類型轉 「YYYY-MM-DD HH:MM:SS」 格式的字元類型。
(3)sql資料庫查詢日期擴展閱讀:
SQL (Structured Query Language) 是具有數據操縱和數據定義等多種功能的資料庫語言,這種語言具有交互性特點,能為用戶提供極大的便利,資料庫管理系統應充分利用SQL語言提高計算機應用系統的工作質量與效率。
條件查詢
條件查詢即帶有WHERE子句的查詢,所要查詢的對象必須滿足WHERE子句給出的條件。
例:找出任何一門課成績在70以上的學生情況、課號及分數
SELECT UNIQUE student.st_class,student.st_no,student.st_name,student.st_sex,student.st_age,score.su_no,score.score
FROM student,score
WHERE score.score>=70 AND score.stno=student,st_no
這里使用UNIQUE是不從查詢結果集中去掉重復行,如果使用DISTINCT則會去掉重復行。另外邏輯運算符的優先順序為NOT→AND→OR。
例:找出課程號為c02的,考試成績不及格的學生
SELECT st_no
FROM score
WHERE su_no=『c02』 AND score<60
Ⅳ SQL 如何查詢日期在一定范圍內的數據
select * from 表 where 日期欄位>='開始日期' and 日期欄位<='截止日期' and convert(char(8),日期欄位,108)>='開始時間' and convert(char(8),日期欄位,108)<='截止時間'。
SELECT * FROM 表明 WHERE 日期欄位名 BETWEEN '20130101' AND '20130130'。
例如:
select * from tb1 where dDate>='2010-11-05' and dDate<='2010-11-15'
and convert(char(8),dDate,108)>='8:00:00' and convert(char(8),dDate,108)<='9:00:00'.
select * from table1where year(d)=2010 and month(d)=7 and day(d) between 1 and 31
and (Datepart(hour,d)>=22 or Datepart(hour,d)<6)
(4)sql資料庫查詢日期擴展閱讀:
SQL查詢日期:
今天的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())=0
昨天的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())=1
7天內的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())<=7
30天內的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())<=30
本月的所有數據:select * from 表名 where DateDiff(mm,datetime類型欄位,getdate())=0
本年的所有數據:select * from 表名 where DateDiff(yy,datetime類型欄位,getdate())=0
參考資料:SQL_網路
Ⅳ SqlServer資料庫中,日期的模糊查詢
1、打開SQL Server Management Studio管理工具,點擊【新建查詢】,新建一個SQL書寫窗口,用於演示SQL的執行。
Ⅵ SQL查詢access資料庫日期
SQL查詢access資料庫日期的方法如下:
1,打開access,點擊創建,點擊查詢設計,打開後切換成SQL語句。
2,在框框中輸入以下語句:SELECT
*
from
學生
where
出生日期=#日期#;
以下以查詢1992/7/11日的學生為例:
3,然後點擊保存,更改表名。點擊運行就可以了,然後把設計視圖切換會數據視圖就可以看到效果了。
Ⅶ SQL查詢access資料庫日期
SQL查詢access資料庫日期的方法如下:
1,打開access,點擊創建,點擊查詢設計,打開後切換成SQL語句。
2,在框框中輸入以下語句:SELECT * from 學生 where 出生日期=#日期#;
以下以查詢1992/7/11日的學生為例: