我有2个查询。首先是
SELECT CASE WHEN WEEKDAY('2017-03-01') <= 5 THEN 5 -
WEEKDAY('2017-03-01') ELSE 0 END + CASE WHEN WEEKDAY('2017-03-03') <= 5 THEN
WEEKDAY('2017-03-03') + 1 ELSE 5 END + (DATEDIFF('2017-03-03',
'2017-03-01') + 1 - (7 - WEEKDAY('2017-03-01')) - (WEEKDAY('2017-03-03') +
1)) DIV 7 * 5 AS w_d
该查询的输出是
w_k
3
第二个是
SELECT count(*) FROM attendence WHERE eid=1 and login < ('2017-03-03' + interval 1 day ) AND login >= '2017-03-01' .
该查询计数的输出(*)
3
我想减去查询1-2。
最佳答案
尝试这个
Select (
(SELECT CASE WHEN WEEKDAY('2017-03-01') <= 5 THEN 5 - WEEKDAY('2017-03-01') ELSE 0 END + CASE WHEN WEEKDAY('2017-03-03') <= 5 THEN WEEKDAY('2017-03-03') + 1 ELSE 5 END + (DATEDIFF('2017-03-03', '2017-03-01') + 1 - (7 - WEEKDAY('2017-03-01')) - (WEEKDAY('2017-03-03') + 1)) DIV 7 * 5) -
(SELECT count() FROM attendence WHERE eid=1 and login < ('2017-03-03' + interval 1 day ) AND login >= '2017-03-01')) AS w_d
关于php - 如何在mysql中减去2个查询?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42808958/