Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
zoe2003
Starting Member
17 Posts |
Posted - 2015-04-20 : 05:53:30
|
Hi,I have this data:client creditCard amount1 A 101 A 201 B 401 C 5 1 C 101 C 20I need to write a query (Oracle) that will return the clientID and the creditCard type with the highest spending :In this case:client creditCard 1 BThank you in advance.Z. |
|
Maithil
Starting Member
29 Posts |
Posted - 2015-04-20 : 06:37:35
|
Hi,This SQL SERVER BlogAsk same in Oracle Blog |
|
|
Maithil
Starting Member
29 Posts |
Posted - 2015-04-20 : 06:40:28
|
SELECT *FROM YourTable where Credit_card =(select Credit_card from Your Table where Amount=(select MAX(Amount) from your Table)) |
|
|
zoe2003
Starting Member
17 Posts |
Posted - 2015-04-20 : 07:57:38
|
quote: Originally posted by Maithil SELECT *FROM YourTable where Credit_card =(select Credit_card from Your Table where Amount=(select MAX(Amount) from your Table))
@Maithil, Thanks, but what if I have more clientIDs, like :client creditCard amount1 A 101 A 201 B 401 C 5 1 C 101 C 202 A 402 D 60I need this result:client creditCard 1 B2 D |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-04-20 : 09:29:25
|
[code]select client, Credit_cardfrom your_tablejoin( select client as max_client, MAX(amount) max_amount from your_table group by client) _on client = max_client and amount = max_amountorder by client[/code] |
|
|
|
|
|