You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQL查询需求:获取数据表两列各自的最大值

Hey there! Let's figure out how to get the maximum values from Column1 and Column2 in your table.

First, let's align on your data and requirements clearly:

Your Table Data

Column1 | Column2
--------+--------
1 | 1
3 | 2
1 | 3
2 | 1
2 | 4

You want to retrieve the highest value from Column1 and the highest value from Column2 separately, right?

The SQL Query You Need

This is straightforward with SQL's MAX() aggregate function. Just run this query (replace your_table_name with the actual name of your table):

SELECT MAX(Column1) AS Max_Column1, MAX(Column2) AS Max_Column2
FROM your_table_name;

Quick Breakdown of the Query

  • MAX(Column1) scans all entries in Column1 and returns the largest value (which is 3 in your sample data)
  • MAX(Column2) does the exact same for Column2 (and for your data, that's 4—quick heads up, your example result mentioned "3 : 2" but that looks like a typo, since Column2 has a 4 in the last row!)
  • The AS keywords assign friendly names to the result columns, so you can easily tell which max corresponds to which original column

Expected Result

When you run this query against your sample data, the output will look like this:

Max_Column1 | Max_Column2
------------+------------
3 | 4

That's all there is to it—this query efficiently grabs both max values in a single pass over your table.


内容的提问来源于stack exchange,提问作者Sami Meskaoui

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:25:47