gpt4 book ai didi

php - 如何在mysql中减去2个查询?

转载 作者:行者123 更新时间:2023-11-29 10:57:30 25 4
gpt4 key购买 nike

我有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com