『壹』 通過輸入時間段,查詢出勤率,遲到次數,早退次數,曠工次數,用的ssh集成,oracle資料庫,怎麼寫查詢方法
--建表sql
Create Table mhl.manualsign --考勤信息表
(ms_id int,--非空 種子,自增1 簽卡Id
user_id Varchar(50) not null,--自增1 簽卡Id
ms_time date not null,-- 非空 簽卡時間
ms_desc Varchar(200) not null,-- 非空 簽卡備注
ms_tag int not null-- 非空 簽卡標記 (1,上班打卡,0,下班打卡)
);
create table mhl.tbl_worktime --上下班時間表
(wt_id int not null,-- 非空 種子,自增1 工作時間Id
wt_uptime Varchar(50) not null,-- 非空 上班時間
wt_downtime Varchar(50) not null-- 非空 下班時間
);
-- mhl.manualsign插入數據
truncate table mhl.manualsign;
insert into mhl.manualsign
select 1,'001', to_date('2012-01-01 08:04:54','yyyy-mm-dd hh24:mi:ss'),'001','1' from al
union
select 2,'001', to_date('2012-01-01 17:04:54','yyyy-mm-dd hh24:mi:ss'),'001','0' from al
union
select 3,'001', to_date('2012-01-02 08:04:54','yyyy-mm-dd hh24:mi:ss'),'001','1' from al
union
select 4,'001', to_date('2012-01-02 18:04:54','yyyy-mm-dd hh24:mi:ss'),'001','0' from al
union
select 5,'001', to_date('2012-01-03 09:04:54','yyyy-mm-dd hh24:mi:ss'),'001','1' from al
union
select 6,'001', to_date('2012-01-03 18:04:54','yyyy-mm-dd hh24:mi:ss'),'001','0' from al
union
select 7,'001', to_date('2012-01-05 08:04:54','yyyy-mm-dd hh24:mi:ss'),'001','1' from al
union
select 8,'001', to_date('2012-01-05 18:04:54','yyyy-mm-dd hh24:mi:ss'),'001','0' from al
union
select 9,'001', to_date('2012-01-07 08:04:54','yyyy-mm-dd hh24:mi:ss'),'001','1' from al
union
select 10,'001', to_date('2012-01-07 18:04:54','yyyy-mm-dd hh24:mi:ss'),'001','0' from al;
insert into mhl.manualsign
select 11,'002', to_date('2012-01-01 08:04:54','yyyy-mm-dd hh24:mi:ss'),'002','1' from al
union
select 12,'002', to_date('2012-01-01 18:04:54','yyyy-mm-dd hh24:mi:ss'),'002','0' from al
union
select 13,'002', to_date('2012-01-02 08:04:54','yyyy-mm-dd hh24:mi:ss'),'002','1' from al
union
select 14,'002', to_date('2012-01-02 18:04:54','yyyy-mm-dd hh24:mi:ss'),'002','0' from al
union
select 15,'002', to_date('2012-01-03 09:04:54','yyyy-mm-dd hh24:mi:ss'),'002','1' from al
union
select 16,'002', to_date('2012-01-03 18:04:54','yyyy-mm-dd hh24:mi:ss'),'002','0' from al
union
select 17,'002', to_date('2012-01-05 08:04:54','yyyy-mm-dd hh24:mi:ss'),'002','1' from al
union
select 18,'002', to_date('2012-01-05 18:04:54','yyyy-mm-dd hh24:mi:ss'),'002','0' from al
union
select 19,'002', to_date('2012-01-07 08:04:54','yyyy-mm-dd hh24:mi:ss'),'002','1' from al
union
select 20,'002', to_date('2012-01-07 18:04:54','yyyy-mm-dd hh24:mi:ss'),'002','0' from al;
--mhl.tbl_worktime插入數據
truncate table mhl.tbl_worktime;
insert into mhl.tbl_worktime
select 1,'2012-01-01 09:00:00','2012-01-01 18:00:00' from al;
----通過輸入時間段,查詢出勤率,遲到次數,早退次數,曠工次數
--設置入參:開始時間為:2012-01-01 結束時間為 2012-01-07
select a.user_id,
(select Count(1) / 2
From mhl.manualsign c
where c.user_id = a.user_id
and c.ms_time >= To_Date('2012-01-01', 'yyyy-mm-dd')
and c.ms_time <= To_Date('2012-01-07', 'yyyy-mm-dd')) /
(select To_Date('2012-01-07', 'yyyy-mm-dd') -
To_Date('2012-01-01', 'yyyy-mm-dd')
from al) 出勤率,
(Select Count(1)
From mhl.manualsign d
where a.user_id = d.user_id
and d.ms_tag = '1'
and To_char(d.ms_time, 'hh24:mi:ss') > To_char('09:00:00')
and d.ms_time >= To_Date('2012-01-01', 'yyyy-mm-dd')
and d.ms_time <= To_Date('2012-01-07', 'yyyy-mm-dd')
and d.user_id = a.user_id) 遲到次數,
(Select Count(1)
From mhl.manualsign d
where a.user_id = d.user_id
and d.ms_tag = '0'
and to_char(d.ms_time, 'hh24:mi:ss') < to_char('18:00:00')
and d.ms_time >= To_Date('2012-01-01', 'yyyy-mm-dd')
and d.ms_time <= To_Date('2012-02-01', 'yyyy-mm-dd')
and d.user_id = a.user_id) 早退次數,
round(round(1 + To_Date('2012-01-07', 'yyyy-mm-dd') -
To_Date('2012-01-01', 'yyyy-mm-dd')) -
(select count(1) / 2
from mhl.manualsign f
where f.user_id = '001'
and f.ms_time >= To_Date('2012-01-01', 'yyyy-mm-dd')
and f.ms_time <= 1 + To_Date('2012-01-07', 'yyyy-mm-dd'))) 曠工次數
from mhl.manualsign a
where a.ms_time between To_Date('2012-01-01', 'yyyy-mm-dd') and /*a.ms_time <=*/
To_Date('2012-01-07', 'yyyy-mm-dd')
group by a.user_id;
『貳』 求助高手啊,出勤率sql語句怎麼寫
你表結構是什麼樣的啊,現在只能給你個思路了,比如這個月全勤是26天,超過或等於26天的就100%,沒超過的,就出勤天數/26就OK了
『叄』 員工考勤統計怎麼寫sql語句,查詢出勤率,遲到次數,早退次數,曠工次數
你的給子段,給點模擬數據
『肆』 sql server中查詢每個班級的出勤率(出勤人數/班級人數),有學員信息表和出勤表(到校和沒到校的都有記錄)怎麼
每個子查詢,查詢出來的結果都有可能是多個,因為你分組了。他會把每個班級的人數進行統計,結果就是多個
這樣就可以了:
select rount(t1.實際出勤人數/t2.班級人數,2) from
(select count(goschool) 實際出勤人數 ,cclass from tx_scheck where goschool='到校' group by cclass) t1
inner join
(select count(*) 班級人數 , sclass from tx_xsxxb a where a.ifgoschool='在校' group by sclass) t2 on t1.cclass = t2.sclass
『伍』 sql 單表查詢語句 求高手幫忙
--總出席的天數
DECLARE @day_count int
select @day_count=count(*) from
(select substring(convert( varchar(10),signtime,120),1,10) a from sign group by substring(convert( varchar(10),signtime,120),1,10)) s;
--考勤表中出現的人
select m1.userid,m1.應考天數,m2.簽到次數,m3.簽退次數,ISNULL(m4.遲到次數,0) 遲到次數,ISNULL(m5.早退次數,0) 早退次數 from (
select userid,@day_count 應考天數 from sign group by userid) m1 left join (
--每人簽到的次數
select count(signid) 簽到次數, userid from sign where signflag=1 group by userid ) m2 on m1.userid=m2.userid left join(
--每人簽退的次數
select count(signid) 簽退次數, userid from sign where signflag=0 group by userid ) m3 on m1.userid=m3.userid left join (
--每人遲到次數
select count(signid) 遲到次數, userid from sign where signflag=1 and convert(varchar(5) ,signtime,114)>'08:00' group by userid ) m4 on m1.userid=m4.userid left join (
--每人早退次數
select count(signid) 早退次數, userid from sign where signflag=0 and convert(varchar(5) ,signtime,114)<'18:00' group by userid) m5 on m1.userid=m5.userid
--把這些語句再用left join 連在一起想要啥就有啥了,都到這步了計算你自己來吧
『陸』 SQL 多表連接效率是否高
現在大多用的是基於成本的優化規則,對於數據的查詢效率,主要依賴於:
總的數據量
索引和統計
檢索的數據量
與內連接、左聯接等等關系不是太大。
『柒』 sql server 循環插入語句
--可以不用循環哦,先建好臨時表,和table201401——table201412的表
--下面的代碼是把滿足table2014%這個條件的表分組統計後插入到臨時表
execsp_MSforeachtable
@command1="insertinto#tempselect姓名,substring('?',13,6),count(日期)
from?groupby姓名",
@whereand="Ando.Namein(SelectnameFromsys.objectsWhereType='U'And
Namelike'table2014%'
)"
--當然循環也行
Declare@NameVarchar(100)
Declare@sqlVarchar(1000)
DECLARECurCURSORFOR
SelectnameFromsys.objectsWherenamelike'table2014%'
OPENCur
FETCHNEXTFROMCurINTO@Name
WHILE@@FETCH_STATUS=0
BEGIN
Set@sql='insertinto#tempselect姓名,right('''+@Name+''',6),count(日期)
from'+@Name+'groupby姓名'
Exec(@sql)
FETCHNEXTFROMCurINTO@Name
END
CLOSECur
DEALLOCATECur
select*from#temp
『捌』 誰能幫我把下面報表用SQL語句寫出來謝謝了!必定重賞!
這個看不懂你寫什麼啊?你給表我們看看才知道怎麼拿賞金啊!
『玖』 跪求哪位高手幫我用SQL語句解決下面的問題,用SQL語句寫出來謝謝!
你的表結構呢?
難道說,是想要 select * from 表名;
『拾』 sql的復雜查詢問題:
no,date,attendance
12 2010-10-10 Y
13 2010-11-12 N
1)
思路:先查工資大於8000,再並列查詢,小於5次
2010年小於5次的
select A.no count(A.no) from Attend A where attendance group by substring(date,0,4) having count(A.no)<5
故,綜上得出結論
select E.no,E.name from Employee E left join Wage W on E.no=W.no left join (select A.no count(A.no) from Attend A where attendance group by substring(date,0,4) having count(A.no)<5)A on E.no=A.no where W.amount > 8000;
2)
思路:先查工資平均數,分別查不同的日期即可
select W.amount/sum(W.amoun),A.no,A.attendance/sum(A.attendance) from Attend A left join Wage W on W.no=A.no where substring(date,0,6)='201212' group by A.no
select W.amount/sum(W.amoun),A.no,A.attendance/sum(A.attendance) from Attend A left join Wage W on W.no=A.no where substring(date,0,6)='201201' group by A.no