如何在SQL QUERY中从计算中抛出WEEKENDS?

时间:2013-01-08 07:45:18

标签: mysql sql weekend

我有SQL查询,它返回前一年某些工人的平均利用率。

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

现在我想排除周末的预约日期进行计算?怎么做?我正在使用mysql 谢谢

1 个答案:

答案 0 :(得分:7)

DAYOFWEEK()添加到您的WHERE子句:

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