gpt4 book ai didi

mysql - 如果mysql中某列的值大于1,则将该列中的值设为1

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

我的 sql 中有一个表。

我已将 count 列中的值除以该列的第 99 个四分位数。我得到了这个结果。

id  count
1 0.3
2 0.5
3 0.7
4 0.9
5 1.3
6 0.1
7 3.2

我使用的计算第 99 个四分位数的代码是:

 SELECT
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(
GROUP_CONCAT(count ORDER BY count SEPARATOR ','),
',', 100/100 * COUNT(*) + 1), ',', -1) AS DECIMAL) AS `95th Per`
FROM table_name;

然后我做了:

select id, (count/(SELECT       
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(
GROUP_CONCAT(count ORDER BY count SEPARATOR ',')
,',', 100/100 * COUNT(*) + 1), ',', -1)
AS DECIMAL) AS `95th Per` FROM table_name) as count1
from table_name.

我现在面临的挑战是

我想每当计数大于 1 时就对列的 = 1 进行计数,就我而言,id=5 和 7

有什么方法可以调整我的查询并获得所需的输出。提前致谢。

The code for calcluation of the quartile was found on this site

最佳答案

尝试将查询包装在另一个类似于

的选择中
Select 
Id,
Case when count > 1 then 1 else count end as count
From (
// place original query here
) t

然后您可以更轻松地操作外部查询来检查计数。我的 case 语法可能有点偏离,但你明白了。

关于mysql - 如果mysql中某列的值大于1,则将该列中的值设为1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989407/

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