开发者

How could I write select statement to these two columns?

开发者 https://www.devze.com 2023-04-10 12:02 出处:网络
Can you write a SQL command for helping me in these two column开发者_运维技巧s? for example.....these two columns

Can you write a SQL command for helping me in these two column开发者_运维技巧s?

for example.....these two columns

a1             a2
______       ______
1              1
2              1
1              2
2              3
3              1
3              2
4              1
4              2

I want the output:

a1 a1
1  2
2  3
3  2
4  2


I'm guessing, based on your example, that you want the second column to be the maximum a2 value for the corresponding a1 value.

Then you want:

SELECT a1, MAX(a2) AS a2 FROM table GROUP BY a1


Basic aggregates:

SELECT a1, MAX(a2) AS a2
  FROM AnonymousTable
 GROUP BY a1;
0

精彩评论

暂无评论...
验证码 换一张
取 消