यदि आपके पास अपनी आरंभ तिथि और समाप्ति तिथि (सहित) के बीच सभी तिथियों वाली कोई तालिका नहीं है, तो आपको एक क्वेरी अपनाने की आवश्यकता है जो पहले आपकी दी गई तिथि सीमा (समावेशी) के बीच सभी तिथियां बनाएगी। फिर WEEKDAY
. का उपयोग करें MySQL
. का कार्य यह जांचने के लिए कि क्या दिन Saturday
है या Sunday
SELECT
dateTable.Day,
DAYNAME(dateTable.Day) AS dayName
FROM
( SELECT ADDDATE('2016-07-01', INTERVAL @i:[email protected]+1 DAY) AS DAY
FROM (
SELECT a.a
FROM (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS a
CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS b
CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS c
) a
JOIN (SELECT @i := -1) r1
WHERE
@i < DATEDIFF('2016-08-01', '2016-07-01')
) AS dateTable
WHERE WEEKDAY(dateTable.Day) IN (5,6)
ORDER BY dateTable.Day;
नोट: WEEKDAY
दिनांक के लिए कार्यदिवस सूचकांक देता है (0 =सोमवार, 1 =मंगलवार, … 6 =रविवार)।
संपादित करें:
अगर आपको केवल count
की जरूरत है :
SELECT
COUNT(*) AS total
FROM
( SELECT ADDDATE('2016-07-01', INTERVAL @i:[email protected]+1 DAY) AS DAY
FROM (
SELECT a.a
FROM (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS a
CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS b
CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS c
) a
JOIN (SELECT @i := -1) r1
WHERE
@i < DATEDIFF('2016-08-01', '2016-07-01')
) AS dateTable
WHERE WEEKDAY(dateTable.Day) IN (5,6)