資料庫中有不連續的日期如何獲取缺失的日期

時間 2022-04-22 07:14:39

1樓:匿名使用者

如果通過vb語言賦值,當前日期函式為date(),包含時間的當前日期函式為now()如果通過資料庫函式賦值,不同的資料庫函式不同,mssql為getdate(),oracle為sysdate

2樓:匿名使用者

最佳答案居然是答非所問,最好的辦法是先建一臨時表tmp_date,產生最小日期到最大日期,然後通過not exists查出來不存在的日期。

比如:with tmp_date as

(select rownum, to_date('20160101','yyyymmdd')+rownum-1 as dd from dual connect by rownum< to_date('20170630','yyyymmdd')- to_date('20160101','yyyymmdd') +2)

select * from tmp_date dwhere not exists (select * from 待查詢的表 t where t.日期=d.dd)

order by d.dd

sql server 如何用一條select語句查出表中一段時間每天的某資料之和 (並且補全缺少的日期)主要

3樓:匿名使用者

可以使用convert函式。

如某錶的日期欄位為datetime

如表為test,日期欄位為statedate,求和欄位為grade。

sql語句:

select convert(varchar(10),statedate,120) statedate,sum(grade) grade from test where convert(varchar(10),statedate,120) between '2015-06-01' and '2015-06-30' group by convert(varchar(10),statedate,120)

4樓:匿名使用者

select count(*),convert(date,max(日期))

from 表 group by convert(date,日期)

union all

select * from

(select 0 co,convert(varchar(10),dateadd(dd,number,convert(varchar(8),getdate(),120)+'01'),120) as dt

from master..spt_values

where type='p'

and dateadd(dd,number,convert(varchar(8),getdate(),120)+'01')<=dateadd(dd,-1,convert(varchar(8),dateadd(mm,1,getdate()),120)+'01')) c

where dt not in (select convert(date,max(日期)) from 表 group by convert(date,日期) )

將表和日期改為相應的表明和日期列名即可

5樓:匿名使用者

select sum(a) as a,convert(varchar(7),date,120) as date

from test group by prokey,convert(varchar(7),date,120)

6樓:匿名使用者

select date, count(id) as c

from test

group by date

如何實現從資料庫中取出所有日期,使用sql語句能夠區分出每年的日期。

7樓:匿名使用者

如何實現從資料庫中取出所有日期,使用sql語句能夠區分出每年的日期。

1、轉成字串

2、再進行擷取

如sql server的語法:

select convert(

varchar(4) -- 特殊技巧,只取前4位,省去擷取函式, getdate()

, 120 -- 格式為yyyy-mm-dd hh;mi;ss)

8樓:匿名使用者

select *,year(createtime) from table1

如何在最少的sql語句中 查詢最近10個日期的資料

9樓:匿名使用者

select a.* ,

sysdate -a.date s

from a

where sysdate-a.date in (1,2,...10)

order by s asc

直接 使用date 代替你那個時間了 表使用a代表了僅僅是我的思路 歡迎共同討論

10樓:匿名使用者

oracle資料庫嗎,可以統一換成一種日期格式,再進行查詢

11樓:匿名使用者

select * from table1 where sp_date in (

select top 10 sp_date from (select distinct sp_date as sp_date from table1 order by sp_date desc) )

資料庫中如何查詢日期為空的資料

12樓:匿名使用者

1、開啟mysql命令列編輯器,連線mysql資料庫。

2、使用想要操作的資料庫,可以先檢視一下資料庫中的表。

3、檢視表結構,準備插入資料。

4、接下來向表中插入資料。

5、輸入 select * from 表名;可以檢視所有資料。

6、輸入select 列名 from 表名;可以檢視資料庫中選中的列。

13樓:匿名使用者

一般為空都用null表示,所以一句sql語句就可以。

select * from 表名 where 日期字段 is null;

這裡要注意null的用法,不可以用=null這樣的形式表示。

測試:建立表插入資料:

create table test

(id int,

insert_date datetime)insert into test values (1,getdate())

insert into test values (2,null)執行:select * from test where insert_date is null;

結果:如果寫成=null,則沒有結果。如:

14樓:匿名使用者

個人認為第一種應該可以找到的吧,你用的是什麼資料庫啊,你沒有說,sql server,access,還是oracle,你可以用select語句根據其他條件讀出來一些時間為空的記錄,看看得到的是什麼結果,然後再根據這個試試。

另外還有乙個想法你可以試一下,大概看看你的日期的範圍,然後用where 《最小時間and >最大時間

剩下的我覺得應該都是空的了吧,你可以試一下

15樓:你以為你以為

mysql :select * from table where time = '';

oracle : slect * from tbale where time = null;

資料庫中獲取的日期如何只顯示年

16樓:鬼谷子教主

1、轉成字串

2、再進行擷取

如sql server的語法:

select convert(

varchar(4) -- 特殊技巧,只取前4位,省去擷取函式, getdate()

, 120 -- 格式為yyyy-mm-dd hh;mi;ss)

17樓:迷戀滴輪迴

select distinct year(time) from table1 //從資料庫表中讀取時間篩選出 年

18樓:匿名使用者

不知道你用的是什麼資料庫,如果為access之類的,則可使用如下形式:

select mid(date,1,4) as stryear,其他字段 from table

其他資料庫也有類似功能,如oracle是substr

19樓:匿名使用者

select ...........where date >= '2010-01-01 00:00:00' and date<='2010-12-31 23:59:59'

20樓:匿名使用者

查詢出來的時候 用c#的datetime.year來輸出唄

關於資料庫中的 資料庫管理系統 資料庫 資料庫系統

1 資料庫管理系統是管理資料庫的軟體系統。2 資料庫是有組織的 可共享的資料的集合。3 資料庫系統由使用者 資料庫管理系統 資料 應用程式和計算機硬體組成。4 其中,資料庫管理系統是資料庫系統的核心。資料庫 data base 為滿足某一部門中多個使用者多種應用的需要,按照一定的資料模型在計算機系統...

資料庫,資料庫管理系統和資料庫系統的區別

資料庫 容納資料的倉庫。資料庫系統 資料庫 資料庫管理系統 硬體 操作人員的合在一起的總稱。資料庫管理系統 用來管理資料及資料庫的系統。資料庫系統包含資料庫管理系統 資料庫及資料庫開發工具所開發的軟體 資料庫應用系統 資料庫系統包括資料庫,資料庫管理系統,應用系統,資料庫管理員所以資料庫系統是個大的...

sqlserver如何查資料庫中有幾張表

select from sysobjects where xtype u 查詢當前資料庫下所有使用者建立的表 追問 麻煩問一下,其中的xtype u 分別是什麼意思?回答 xtype char 2 物件型別 可以是下列物件型別中的一種 c check 約束 d 預設值或 default 約束 f f...

關於資料庫oracle的問題,關於資料庫oracle的問題

你是指的oracle的資料庫產品的相關操作吧。oracle有乙個 管理工具 sqlplus,可以在window cmd啟動,也可以單獨開啟視窗啟動,使用sql語句對資料庫進行操作。同時也有視覺化的操作工具 em.啟動em管理資料庫,也需要很多的sql語句才可以對錶空間,段,索引等等進行操作。建立資料...

資料庫之間的區別,資料庫中 和 的區別

oracle 適用於較大型系統,但上手比較困難,即便上手後也很難提高。需要有長期的實踐和摸索,但確實比較適合大系統。備份與恢復比較完善,但必需很有經驗才能做的比較好。資料量不超過1t,可以用它 sqlserver 個人認為ms平台下最好用的資料庫。介面簡單友好,操作方便,備份與恢復都比較容易學會。而...