gpt4 book ai didi

mysql - mysql 销售额环比增长

转载 作者:行者123 更新时间:2023-11-29 17:50:18 27 4
gpt4 key购买 nike

首先我不是数据库专家。我自己创建了一个数据库并成功运行了一些查询。我现在想要计算下一个月的最高 ach%,然后使用结果与下个月进行比较。

例如,我有 7 月 ach % 和 8 月 ach %,这两个月的结果将与 9 月 ach % 进行比较。我现在使用查询所做的事情就在帖子中。我想要的是如何在查询中的所有月份执行此操作?

代码:

`associate_monthly_ach_percentage`.`Team Name` AS `Team Name`,
`associate_monthly_ach_percentage`.`CCRS ID` AS `CCRS ID`,
`associate_monthly_ach_percentage`.`Associate Name` AS `Associate Name`,
`associate_monthly_ach_percentage`.`Desgination` AS `Desgination`,
`associate_monthly_ach_percentage`.`Date of Joining` AS `Date of Joining`,
`associate_monthly_ach_percentage`.`Ach % Jul` AS `Ach % Jul`,
`associate_monthly_ach_percentage`.`Ach % Aug` AS `Ach % Aug`,
( CASE
WHEN ( `associate_monthly_ach_percentage`.`Ach % Aug` >=
`associate_monthly_ach_percentage`.`Ach % Jul` )
THEN `associate_monthly_ach_percentage`.`Ach % Aug`
ELSE `associate_monthly_ach_percentage`.`Ach % Jul` END ) AS `Highest Ach Jul to Aug`,
`associate_monthly_ach_percentage`.`Ach % Sep` AS `Ach % Sep`

我卡在这里,无法想到如何将这个结果与 9 月 Ach % 的月份进行比较。上面的查询运行完美并正确显示所需的数据。对此的任何帮助将不胜感激。提前致谢。

以上查询结果:

Team Name   CCRS ID Associate Name  Desgination DOJ Ach%Jul Ach%Aug Highest AchJultoAug Ach%Sep

Cardio Hospital 102 Musawar Jaan H.C.R 4/1/2011 122 118 122 103
Cardio Hospital 103 Zulfiqar Ali Khan H.C.R 7/11/2016 118 118 118 87
Cardio Hospital 104 Hameed Ur Rehman H.C.R 6/7/2009 90 79 90 103
Cardio Hospital 1101 Muhammad Ahmed H.C.R 9/3/2011 85 96 96 79

SQLFIDDLE 链接

http://www.sqlfiddle.com/#!9/a93816

添加虚拟数据以检查查询。

最佳答案

试试这个,

我从您生成的表中查询如下,

希望这能解决您的问题

    SELECT
`associate_monthly_ach_percentage`.`CCRS ID` AS `CCRS ID`,
`associate_monthly_ach_percentage`.`Associate Name` AS `Associate Name`,
`associate_monthly_ach_percentage`.`Date of Joining` AS `Date of Joining`,
`associate_monthly_ach_percentage`.`Ach % Jul` AS `Ach % Jul`,
`associate_monthly_ach_percentage`.`Ach % Aug` AS `Ach % Aug`,
GREATEST(`associate_monthly_ach_percentage`.`Ach % Jul`, `associate_monthly_ach_percentage`.`Ach % Aug`) AS `Highest Ach Jul to Aug`,
`associate_monthly_ach_percentage`.`Ach % Sep` AS `Ach % Sep`,
GREATEST(`associate_monthly_ach_percentage`.`Ach % Aug`,`associate_monthly_ach_percentage`.`Ach % Sep`) AS `Highest Ach Aug to Sep`,
`associate_monthly_ach_percentage`.`Ach % Oct` AS `Ach % Oct`,
GREATEST(`associate_monthly_ach_percentage`.`Ach % Sep`,`associate_monthly_ach_percentage`.`Ach % Oct`) AS `Highest Ach Sep to Oct`,
`associate_monthly_ach_percentage`.`Ach % Nov` AS `Ach % Nov`,
GREATEST(`associate_monthly_ach_percentage`.`Ach % Oct`,`associate_monthly_ach_percentage`.`Ach % Nov`) AS `Highest Ach Sep to Nov`,
`associate_monthly_ach_percentage`.`Ach % Dec` AS `Ach % Dec`,
GREATEST(`associate_monthly_ach_percentage`.`Ach % Nov`,`associate_monthly_ach_percentage`.`Ach % Dec`) AS `Highest Ach Sep to Dec` FROM
`associate_monthly_ach_percentage`;

关于mysql - mysql 销售额环比增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49422404/

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