开发者

How could I write select statement to 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜