MySQL LEAST() 函数不返回结果的问题

发布于 2024-10-17 18:13:57 字数 1101 浏览 1 评论 0原文

我最近在查询中使用 LEAST(tb1, tb2, tb3) AS 名称来获取多个列中的最小值,并检查它们是否不等于默认值 0.00

到目前为止,它工作正常并且符合我的预期,同样,远程服务器上的脚本版本运行良好。

但是,在更改列默认值和 NULL 状态之后(我试图查看是否可以使用 NULL 而不是 0.00,在阅读了 LEAST 文档后,这不是我想要做的。),然后重新导入表我本来就是用的。它仍然无法像以前那样工作,没有明显的原因,我使用 LEAST() 的查询根本不返回任何内容,空数组,并且没有可见的错误消息。

我已经重新启动了 MySQL,刷新了表,提取了远程脚本以在我的开发服务器上进行测试,但似乎没有任何效果。

在我的开发服务器和远程服务器上通过 phpmyadmin 在表上运行相同的查询会返回相反的结果,本地返回零行,远程返回行,两者上都有相同的 EXPLAIN 结果(除了表中的#rows)。

从查询中删除 LEAST() 函数确实会在我的开发服务器上返回数据。

以下是一个示例查询:

SELECT id, make, model, LEAST(r24ch10k, r36ch10k, r24ch15k, r36ch15k, r24ch20k, r36ch20k) AS lowest 
    FROM xml 
    WHERE LEAST(r24ch10k, r36ch10k, r24ch15k, r36ch15k, r24ch20k, r36ch20k) != 0.00         
    ORDER BY lowest LIMIT 5

我的本地服务器信息
服务器版本:5.1.51-community
Apache/2.2.16 (Win32) PHP/5.3.3
MySQL 客户端版本:mysqlnd 5.0.7-dev - 091210 - $修订版:300533 $
PHP 扩展:mysqli

我的远程服务器信息
服务器版本:5.0.51a-24+lenny5
Apache/2.2.16 PHP/5.3.3
MySQL客户端版本:5.0.51a
PHP 扩展:mysql

帮助解决这个问题将不胜感激。

I've been recently using LEAST(tb1, tb2, tb3) AS name within my queries to fetch minimal values across multiple columns and check whether they were not equal to a default value of 0.00

So far it was working correctly and as intended for me, as well, the version of the script on a remote server is working fine.

However, after changing column defaults and NULL status (I was attempting to see if i could use NULL as opposed to 0.00, which after reading the LEAST documentation would not have been what I wanted to do.) and then afterwards re-importing the table I was originally using. It still will not work as it did before, for no apparent reason, my queries that use LEAST() return nothing at all, empty arrays, and no visible error messages.

I have restarted MySQL, Flushed the tables, pulled the remote script to test on my dev server, and nothing seems to work.

Running the same query on the table via phpmyadmin on both my dev and remote server returns opposite results, locally it returns zero rows, remotely it returns rows, with the same EXPLAIN result on both(aside from #rows in the table).

Removing the LEAST() functions from the queries, does return data on my dev server.

Here is an example query:

SELECT id, make, model, LEAST(r24ch10k, r36ch10k, r24ch15k, r36ch15k, r24ch20k, r36ch20k) AS lowest 
    FROM xml 
    WHERE LEAST(r24ch10k, r36ch10k, r24ch15k, r36ch15k, r24ch20k, r36ch20k) != 0.00         
    ORDER BY lowest LIMIT 5

My Local Server Information:
Server Version: 5.1.51-community
Apache/2.2.16 (Win32) PHP/5.3.3
MySQL client version: mysqlnd 5.0.7-dev - 091210 - $Revision: 300533 $
PHP extension: mysqli

My Remote Server Information:
Server version: 5.0.51a-24+lenny5
Apache/2.2.16 PHP/5.3.3
MySQL client version: 5.0.51a
PHP extension: mysql

Help in resolving this issue would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

予囚 2024-10-24 18:13:57

不知道这是否有帮助,LEAST()

在 MySQL 5.0.13 之前,LEAST() 返回
仅当所有参数均为 NULL 时才为 NULL。
从 5.0.13 开始,如果有则返回 NULL
参数为 NULL。

Don't know if this helps, LEAST()

Before MySQL 5.0.13, LEAST() returns
NULL only if all arguments are NULL.
As of 5.0.13, it returns NULL if any
argument is NULL.

蓬勃野心 2024-10-24 18:13:57

我在 MySQL 论坛的一些帮助下找到了答案。

由于我正在寻找的是最低值,因此将默认值设置为可能的最低值是我犯错误的地方。

我已将列的默认值设置为较高的值(9999999999.99),添加到这些列的值永远不会超过默认值。

所以

WHERE LEAST(col1, col2, col3) != 0.00

我会用

WHERE LEAST(col1, col2, col3) != 99999999999.99

I figured the answer out with some help at the MySQL forums.

Since what I was looking for was the lowest value, setting the default value to be the lowest possible value is where I err'ed.

I have set the default value for the columns to a high value (9999999999.99), the values added to these columns will never exceed the default value.

So instead of

WHERE LEAST(col1, col2, col3) != 0.00

I would use

WHERE LEAST(col1, col2, col3) != 99999999999.99
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文