SQLite3中按時間範圍分類排名 top 10

2021-05-28 12:27:39 字數 2936 閱讀 5862

時間單位是c#中的datetime.tofiletime() / 1000000000

建立表:

create table

if not exists

table_wpp_status(

wpp_id integer primary key autoincrement not null,

wpp_sn varchar(64) not null,

wpp_emp_id varchar(32) not null,

wpp_class varchar(32) not null,

wpp_state integer default(0),

wpp_in_time integer default(0),

wpp_out_time integer default(0))

插入表資料:

insert into

table_wpp_status(

wpp_sn,

wpp_emp_id,

wpp_class,

wpp_state,

wpp_in_time,

wpp_out_time)

values

('xbx20091021',

'perry1',

'abc',

0,129384821,

0)insert into

table_wpp_status(

wpp_sn,

wpp_emp_id,

wpp_class,

wpp_state,

wpp_in_time,

wpp_out_time)

values

('xbx20091022',

'perry2',

'abc',

0,129384824,

0)insert into

table_wpp_status(

wpp_sn,

wpp_emp_id,

wpp_class,

wpp_state,

wpp_in_time,

wpp_out_time)

values

('xbx20091023',

'perry3',

'abc',

0,129384829,

0)insert into

table_wpp_status(

wpp_sn,

wpp_emp_id,

wpp_class,

wpp_state,

wpp_in_time,

wpp_out_time)

values

('xbx20091024',

'perry3',

'abc',

0,129384830,

0)

修改資料:

update

table_wpp_status

set wpp_state = 1,

wpp_out_time = 129384848

where

wpp_sn='xbx20091022' and

wpp_class='abc' and

wpp_state = 0

update

table_wpp_status

set wpp_state = 1,

wpp_out_time = 129384848

where

wpp_sn='xbx20091023' and

wpp_class='abc' and

wpp_state = 0

update

table_wpp_status

set wpp_state = 1,

wpp_out_time = 129384848

where

wpp_sn='xbx20091024' and

wpp_class='abc' and

wpp_state = 0

查詢資料:

select

s1.wpp_emp_id as emp_id,

count(s1.wpp_id) as total_input,

count

( case when

s1.wpp_state >= 1 and

s1.wpp_out_time >= 129382848

then

s1.wpp_id

end) as total_output

from

table_wpp_status as s1

where

s1.wpp_class = 'abc' and

s1.wpp_emp_id in

( select

distinct s2.wpp_emp_id

from

table_wpp_status as s2

where

s2.wpp_in_time >= 129382848) and

s1.wpp_in_time >= 129382848

group by

s1.wpp_emp_id

order by

total_output desc

limit

10;

輸出結果:

emp_id     total_input      total_output

perry3 2 2

perry2 1 1

perry1 1 0

sqlite3中日期 時間相關操作

strftime 函式可以把yyyy mm dd hh mm ss格式的日期字串轉換成其它形式的字串。strftime 的語法是strftime 格式,日期 時間,修正符,修正符,它可以用以下的符號對日期和時間進行格式化 d 月份,01 31 f 小數形式的秒,ss.sss h 小時,00 23 j...

SQLite3中TimeStamp的使用問題

color blue 在使用sqlite3時使用了timestamp,但是遇到一些問題,現總結如下 一 我的sql語句 create table logs id integer primary key,idcardno varchar 50 createdtime timestamp not nul...

Django中SQLite3的使用

from django.db import models class blogarticle models.model title models.charfield max length 50 author models.charfield max length 20 time models.int...