aldoblack
aldoblack

Reputation: 175

How to get max value of a column based on value of another column?

In my Database I have a table called ARTICLES. In ARTICLES I have 2 columns.

enter image description here enter image description here

Now I want to get the max value of NRRENDORDOK column where the TIP column has value 'A'.

e.g. the max number of cells A in TIP column is 8.

Any help will be appreciated.

Upvotes: 2

Views: 680

Answers (4)

Rezoan
Rezoan

Reputation: 1787

Use SQL MAX() aggregate function

select Max(NRRENDORDOK) from table where tip='A'

Upvotes: 2

M.Ali
M.Ali

Reputation: 69514

SELECT TOP 1 nrreddordok
FROM TableName
WHERE Tip = 'A'
ORDER BY nrreddordok DESC

Upvotes: 1

Madhivanan
Madhivanan

Reputation: 13700

SELECT tip, MAX(nrreddordok) FROM table 
where tip='A'
GROUP BY tip

Upvotes: 2

Michael Mairegger
Michael Mairegger

Reputation: 7301

You should take use of the MAX function and then GOUP BY tip in order to get the max value for each tip:

SELECT tip, MAX(nrreddordok) FROM table GROUP BY tip

If you just want values for A then you can use following query:

SELECT MAX(nrreddordok) FROM table WHERE tip = 'A'

Upvotes: 1

Related Questions