Take case... When... Then... End output

Source: Internet
Author: User
Select date, name, (Case Attendance Status when 'White shift 'then' ○ 'end) as white shift, (Case Attendance Status when 'Night shift 'then' ○ 'end) as night shift, (Case Attendance Status when 'then' ○ 'end) as rest, (Case Attendance Status when' shift 'then' ○ 'end) as shift, (Case Attendance Status when 'theen' ○ 'end) as sick leave, (Case Attendance Status when' false 'then' ○ 'end) as false, (Case Attendance Status when' late 'then' ○ 'end) as late, (Case Attendance Status when' early return 'then' ○ 'end) as early leave, (Case Attendance Status when 'absenteeism 'then' ○ 'end) as absenteeism, (Case Attendance Status when' other 'then' ○ 'end) as others, departments, ID card numbers, ID from DBO. personnel _ attendance table where (Department = @ Department) and (date = @ date)

'Collect the daily attendance data of a department by Attendance Status
Select date, department,
Count (Case Attendance Status when 'White shift 'then' ○ 'end) as white shift,
Count (Case Attendance Status when 'then' ○ 'end) as night shift,
Count (Case Attendance Status when 'resting 'then' ○ 'end) as resting,
Count (Case Attendance Status when 'retreat 'then' ○ 'end) as retreat,
Count (Case Attendance Status when 'theen' ○ 'end) as sick leave,
Count (Case Attendance Status when 'false 'then' ○ 'end) as false,
Count (Case Attendance Status when 'late' then' ○ 'end) as late,
Count (Case Attendance Status when 'Leave early 'then' ○ 'end) as leave early,
Count (Case Attendance Status when 'absenteeism 'then' ○ 'end) as absenteeism,
Count (Case Attendance Status when 'others' then' ○ 'end) as others
From DBO. Personnel _ attendance table
Where Department = 'device tools'
Group by date, Department
Order by date DESC

 

'Attendance status of each organization is calculated on a monthly basis.
Select STR (Year (date) + '-' + ltrim (STR (month (date) as date, department, count (Case Attendance Status when 'White shift 'then' ○ 'end) as white shift,
Count (Case Attendance Status when 'then' ○ 'end) as night shift, count (Case Attendance Status when' resting 'then' ○ 'end) as rest,
Count (Case Attendance Status when 'retreat 'then' ○ 'end) as retreat, count (Case Attendance Status when' sick leave 'then' ○ 'end) as sick leave,
Count (Case Attendance Status when 'then' ○ 'end) as leave, count (Case Attendance Status when' late 'then' ○ 'end) as late,
Count (Case Attendance Status when 'leaving early 'then' ○ 'end) as leaving early, count (Case Attendance Status when 'absenteeism 'then' ○ 'end) as absenteeism,
Count (Case Attendance Status when 'others' then' ○ 'end) as others
From DBO. Personnel _ attendance table
Where (Department = @ Department) and (Year (date) = year (@ date ))
Group by STR (Year (date) + '-' + ltrim (STR (month (date), Department
Order by STR (Year (date) + '-' + ltrim (STR (month (date) DESC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.