sql - Count number of cases -


i have table called leaves has employee id, leave type , date. example, if employee id = 1234 applies sick leave 1-june-2014 5-june-2014, stored in leave tables day day, means following records added: 1234 sick leave 1-june-2014 1234 sick leave 2-june-2014 1234 sick leave 3-june-2014 1234 sick leave 4-june-2014 1234 sick leave 5-june-2014 considered 1 case. clarify mean case: total cases how many leave request had been applied… example: enter image description here need following information sql statement (i should determine period: 1-january-2014 30-december-2014, example):

sick leave cases: 2

escort leave cases: 2

study leave cases: 1

i using postgresql 9.2.

this design bit strange, because of these daily rows, if same person have several escort leaves, have figure out different cases.

for case can use this

select count(*), leavetype  (   select leavetype   leaves   group employee_id, leavetype ) group leavetype; 

my suggestion use case_start , case_end dates 1 case row.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -