gpt4 book ai didi

mysql - 根据条件 fork 累积 _sum

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

我在 mysql 中有表“cumul_sum”,我想根据条件划分“cumulative”列,即如果此列中的值 >= 70,则这些值应存储在名为“others”的新列中"并且前面应该存放对应的sku_id,这里是mytable的结构

sku_id   cumulative
1 10
20 20
13 30
24 50
9 80
4 100

这是我的期待

sku_id    cumulative    sku_id_1    others
1 10 9 80
20 20 4 100
13 30
24 50


Is this any way possible

如果是请帮忙提前致谢

最佳答案

这看起来不像是 sql 查询的工作,相反,您应该在 UI 中处理该格式。

所以只需创建两个查询。

SELECT sku_id, comulative
FROM YourTable
WHERE comulative < 70

SELECT sku_id, comulative as others
FROM YourTable
WHERE comulative >= 70

如果你在 php 或类似的东西上显示(这不是真正的代码)

$size1 = query1.length;
$size2 = query2.length;
if ($size1`> $size2)
$total = $size1
else
$total = $size2

<table>
for ($i = 1 to $total)
{
<tr>
<td> if ($i <= $size1) echo $query1[$i]; </td>
<td> if ($i <= $size2) echo $query2[$i]; </td>
</tr>
}
</table>

关于mysql - 根据条件 fork 累积 _sum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35593148/

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