SQL
1SELECT
2SUM(fee) AS total_fee
3FROM
4users
5WHERE WEEKDAY(created_at) BETWEEN 1 AND 5
追記
平日のそれぞれの売上と、その集計
(土日どうする?)
SQL
1create table users(id int primary key,fee int,created_at date);
2insert into users values
3(1,100,'2021-10-01'),
4(2,150,'2021-10-01'),
5(3,200,'2021-10-02'),
6(4,300,'2021-10-03'),
7(5,120,'2021-10-04'),
8(6,130,'2021-10-05'),
9(7,400,'2021-10-05');
10/*適当なデータ*/
11
12SELECT
13WEEKDAY(created_at) as week,
14SUM(fee) AS total_fee
15FROM
16users
17WHERE WEEKDAY(created_at) BETWEEN 1 AND 5
18GROUP BY
19week
20with rollup
平日の集計だけ
SQL
1SELECT * FROM(
2SELECT
3case when WEEKDAY(created_at) BETWEEN 1 AND 5 then 1 else 0 end as heijitu,
4WEEKDAY(created_at) as week,
5SUM(fee) AS total_fee
6FROM
7users
8GROUP BY
9heijitu,week with rollup
10having week is not null or week is null and heijitu=1
11) as sub
12order by week is null,week
13
※平日だけ集計して行を増やすのは合理的ではないのであまりおすすめできません
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/10/01 08:31
退会済みユーザー
2021/10/01 08:34
2021/10/01 08:37
2021/10/01 08:46
2021/10/01 10:01
2021/10/01 10:28
退会済みユーザー
2021/10/01 10:54