Mysql min 函数作用于列和整数
我有一个表,其中包含名为 size 的列。
我想用 min 函数来查找大小和一组整数的最小值。
例如 : 尺寸可以是:5、10、15 我想找到一组中的最小结果,例如: MIN(size,1)
Min 方法似乎没有几个参数...
我尝试过类似的方法:
SELECT min(1, size) FROM myTable
SELECT min(SELECT 1,size FROM myTable) FROM myTable
这些语法中的每一个都有错误。 我精确地说,我无法在代码中进行比较,因为 sql 是生成的,并且可能更复杂,例如:
SELECT min(SELECT size FROM table1, SELECT size FROM table2, 10)
FROM table3
有什么想法吗?
I've got a table which contains a column named size.
I want with a min function to find the min value of size and a set of integer.
For example :
Size can be : 5, 10, 15
And I want to find the min result in a set like :
MIN(size,1)
Min method does not seem to have several parameters...
I've tried something like:
SELECT min(1, size) FROM myTable
SELECT min(SELECT 1,size FROM myTable) FROM myTable
There is error for each of these syntax.
I precise that I can't do the comparison in my code because the sql is generated and can be something more complex like:
SELECT min(SELECT size FROM table1, SELECT size FROM table2, 10)
FROM table3
Any idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
least
查找跨列/表达式的最小值,min
查找跨行的最小值。或者这实际上可能会更有效
You can use
least
to find the minimum across columns/expressions andmin
to find the minimum across rows.Or this would probably be more efficient actually