gpt4 book ai didi

mysql - 如何根据相同的列名对行值进行分组

转载 作者:行者123 更新时间:2023-11-29 09:29:22 24 4
gpt4 key购买 nike

我已经在 SQL Fiddle 上创建了架构和查询:SQL fiddle ( http://sqlfiddle.com/#!9/e43a13/1 )

我正在尝试根据紧急程度和学术水平获取工作类型的价格,我成功地获取了该价格,但我不知道如何以这种方式格式化它:

| Urgency | Academic Level Name 1   |      Academic Level 2    |     Academic Level 3     |
-------------------------------------------------------------------------------------------
| 1 hour |Price Of Academic Level 1|Price Of Academic Level 2 | Price Of Academic Level 3|
-------------------------------------------------------------------------------------------

我的输出是:

enter image description here

最佳答案

如果您尝试按紧急程度分组,您可以考虑以下查询。

SELECT 
utt.UrgencyTime as `Urgency`
, sum(case when al.AcademicID = 1 then wtd.Price else 0 end) as `Academic Level Name 1`
, sum(case when al.AcademicID = 2 then wtd.Price else 0 end) as `Academic Level Name 2`
, sum(case when al.AcademicID >= 3 then wtd.Price else 0 end) as `Academic Level Name 3`
FROM `WorkTypeData` wtd
JOIN UrgencyTimeTable utt ON utt.UrgencyID = wtd.UrgencyID
JOIN WorkType wt ON wt.WorkTypeID = wtd.WorkTypeID
JOIN AcademicLevel al ON al.AcademicID = wtd.AcademicLevelID
WHERE wt.WorkTypeID = '1'
GROUP BY utt.UrgencyTime

关于mysql - 如何根据相同的列名对行值进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59026259/

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