通过maximum()检测查询字段
我正在使用 mysql GREATEST() 函数从任一列(苹果或桃子)中选择最大整数值。
+----+------------------+
| id | apples | peaches |
+----+------------------+
| 1 | 8 | 4 |
| 2 | 2 | 6 |
| 3 | 3 | 9 |
| 4 | 7 | 2 |
| 5 | 4 | 4 |
+----+------------------+
使用 $result = "SELECT GREATEST(apples,peches) FROM table";
和 echo $result
,我得到:
8
6
9
7
在每个值旁边,我想回显相应的水果名称和水果图标。如何通过MYSQL查询得到下图?
另外,请注意 GREATEST()
函数不会显示相等的值。有没有办法也显示相等的值?
I'm using the mysql GREATEST() function to select the highest integer value from either column (apples or peaches).
+----+------------------+
| id | apples | peaches |
+----+------------------+
| 1 | 8 | 4 |
| 2 | 2 | 6 |
| 3 | 3 | 9 |
| 4 | 7 | 2 |
| 5 | 4 | 4 |
+----+------------------+
Using $result = "SELECT GREATEST(apples, peaches) FROM table";
and echo $result
, I get:
8
6
9
7
Next to each value, I want to echo the corresponding fruit name and a fruit icon. How can I achieve the image below via the MYSQL query?
Also, notice that equal values aren't displayed by the GREATEST()
function. Is there a way to display the equal value as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者,如果您不希望苹果成为平等的默认值,并且想知道两种水果何时平等地代表:
or, if you don't want apples to be the default on equal and want to know when both fruits are equally represented: