gpt4 book ai didi

c# - mysql如何计算出生月份每个类和列是类

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

mysql 数据库中的数据如下所示,并在 WPF 的 Datagrid 中显示结果

 ---------------------------
class student_ID birthday
A 1 2000/1/1
A 5 2001/4/1
B 2 2000/1/12
C 3 2001/8/5
. . .
. . .
Z 1000 2000/12/2
---------------------------

我知道使用 group by 和 rollup 可以选择小计和总计

但我不知道如何做统计表

----------------------------------
month\class A B C ... Z
JAN 1 2 3 ... 0
FEB 0 5 6 ... 7
. . . .
. . . .
DEC 4 8 6 ... 1
----------------------------------

我的方法之一是每个月使用case,但是如果问题变成统计日期而不是月份,365列是不可能的。

谷歌解决问题的方法是什么?

最佳答案

关于:

select
monthname(birthday),
sum(case when class = 'A' then 1 end) as a,
sum(case when class = 'B' then 1 end) as b,
-- add the other 24 letters here
from my_table
group by monthname(birthday)

关于c# - mysql如何计算出生月份每个类和列是类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53839066/

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