Table Name: Price
City Gold_Rate Silver_Rate Date
Mumbai 3000 60 13-07-2014
Delhi 4000 50 14-04-2014
Bangalore 1400 40 16-06-2014
Mumbai 1500 58 18-09-2014
Mumbai 2500 54 19-08-2014
Delhi 1800 60 01-10-2014
Bangalore 1700 44 02-03-2014
Expected Output will be ;
City Gold_Rate Silver_Rate Date
Mumbai 1500 58 18-09-2014
Delhi 1800 60 01-10-2014
Bangalore 1400 40 16-06-2014
I need query for getting this output
can anyone help me out of this issue?
select City,Gold_Rate,Silver_Rate,max(Date) from Price group by City
试试这个查询。
It seems to me that you want your results to be fetched on the basis of minimum Gold_Rates,hence query is
select City,min(Gold_Rate),Silver_rate,Date from Price group by City;
and if you want to fetch the result on the basis of latest date then try this,
select City,Gold_Rate,Silver_Rate,max(Date) from Price group by City;
and according to the requirements you mentioned in the comments,to be more precisely you will use this Select city, gold_rate, silver_rate,date from price where Date in (select max(Date) from price group by city);
select * from price where gold_rate = (select min(gold_rate) from price p where p.city = price.city);
or you can make it use of inner joins
select * from price inner join (
select min(gold_rate) gold_rate, city
from price
group by city
) as ip on ip.city = price.city and ip.gold_rate = price.gold_rate
Both will give you the required output. Good day
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.