gpt4 book ai didi

mysql - 如何将列的最大值存储为变量,然后将其用于 MySQL 中的计算?

转载 作者:行者123 更新时间:2023-11-30 22:18:41 25 4
gpt4 key购买 nike

这是我正在使用的代码。

  Select max(heart_rate) as Max_heart, Count(*) from exercise_logs 
where heart_rate between (0.5*Max_heart) and (0.9*Max_heart);

我是 SQL 的新手,但我认为使用 R 之类的东西会很容易。无论如何,因为我需要在 SQL 中完成这项工作,请问我有什么关于如何做到这一点的建议吗?

我的数据是这样的

  type            minutes calories heart_rate
biking 30 100 110
biking 10 30 105
dancing 15 200 120
dancing 15 165 120
tree climbing 30 70 90
tree climbing 25 72 80
rowing 30 70 90
hiking 60 80 85

最佳答案

您想使用 User-Defined Variables .应该是这样的

  declare var1, var2 INT;

Select var1 = max(heart_rate), var2 = Count(*)
from exercise_logs
where heart_rate between (0.5*Max_heart) and (0.9*Max_heart);

select var1 + var2 as Data;

关于mysql - 如何将列的最大值存储为变量,然后将其用于 MySQL 中的计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37370365/

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