Stefke
Stefke

Reputation: 141

How to throw out WEEKENDS from calculation in SQL QUERY?

I have SQL query which returns average utilization for some worker for previous year.

SELECT Name, AVG (hsum)
FROM
(
    SELECT Name,sum((number_hours)/8)*100 AS hsum
    FROM
    T1
    WHERE name='PERSON_A' and bookeddate>='2012-01-01' and booked_date<='2012-12-31'
    GROUP BY name,booked_date
) t

Now I want to exclude weekends for booked date for calculation? how to do it? I am using mysql thank you

Upvotes: 1

Views: 6689

Answers (1)

Bart Friederichs
Bart Friederichs

Reputation: 33511

Add DAYOFWEEK() to your WHERE clause:

 AND DAYOFWEEK(booked_date) <> 1 AND DAYOFWEEK(booked_date)<>7

Upvotes: 8

Related Questions