gpt4 book ai didi

MySQL查询分配错误

转载 作者:行者123 更新时间:2023-11-29 02:20:19 25 4
gpt4 key购买 nike

当我关注查询时

Select
case
when (@nume=Start_Date) then null
when (@nume!=Start_Date) then @num
End,
case
when (@nume=Start_Date and @nume:=End_Date) then null
when (@nume!=Start_Date) then @nume
End,
case
when (@nume!=Start_Date and @nume:=End_Date and @num:=Start_Date) then @nume
End
from P,(Select @num:=(Select Start_Date from P order by Start_Date desc Limit 1),@nume:=(Select End_Date from P order by Start_Date desc Limit 1 )) as A
;

在下一轮中,它将整数 1 值分配给 @nume,而不是它应该分配给 Date。

最佳答案

“如其所愿”。嗯,documentation明确指出:

As a general rule, other than in SET statements, you should never assign a value to a user variable and read the value within the same statement. For example, to increment a variable, this is okay:

SET @a = @a + 1;

For other statements, such as SELECT, you might get the results you expect, but this is not guaranteed. In the following statement, you might think that MySQL will evaluate @a first and then do an assignment second:

SELECT @a, @a:=@a+1, ...;

However, the order of evaluation for expressions involving user variables is undefined.

您对您的代码应该做什么的解释与文档直接矛盾。我建议您问另一个问题,描述您要解决的问题,并包括样本数据和期望的结果。

关于MySQL查询分配错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014589/

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