標籤:processor arch nts private arc 精度 時間 machine html
比如我有個用SQLite Studio建立的Sqlite3類型資料庫,裡面有個表名為StatisticsData的表結構是 :
-- 表:StatisticsDataCREATE TABLE "StatisticsData" ("Id" TEXT NOT NULL,"MachineName" NVARCHAR,"SessionId" INTEGER,"ProcessId" INTEGER,"ProcessName" NVARCHAR,"ProcessRunningStatus" NVARCHAR,"WorkingSetMemory" NVARCHAR,"WorkingSetPrivateMemory" NVARCHAR,"WorkingSetPeak" NVARCHAR,"ThreadCount" NVARCHAR,"HandleCount" NVARCHAR,"TotalProcessorTime" NVARCHAR,"UserProcessorTime" NVARCHAR,"PrivilegedProcessorTime" NVARCHAR,"StartTime" DATETIME,"ExitTime" DATETIME,"Domain" NVARCHAR,"UserName" NVARCHAR,"FileName" NVARCHAR,"Arguments" NVARCHAR,"WorkingDirectory" NVARCHAR,"CreatedTime" DATETIME,PRIMARY KEY ("Id" ASC),CONSTRAINT "PK_Id" UNIQUE ("Id" ASC))
舉例:
今天是2017-08-10,要刪除7天前的資料,也就是說,所有小於等於2017-08-03都要被刪掉。
寫法1:忽略時間精度,直接比較日期,刪除N天前的資料。
DELETE FROM StatisticsData WHERE date(‘now‘, ‘-7 day‘) >= date(CreatedTime);
寫法2:計算時間精度,比較日期和時間,刪除N天前的資料。
DELETE FROM StatisticsData WHERE julianday(‘now‘) - julianday(CreatedTime) >= 7;
有關時間運算和比較函數的官方教程:http://www.sqlite.org/lang_datefunc.html
翻譯自官網的中文參考:http://www.cnblogs.com/ygm900/p/4460644.html
SQLite的時間差判斷--刪除N天前的資料的兩種寫法