简体   繁体   中英

MYSQL MAX and Min query

Hi could someone help me with this problem for my college homework assignment

cars

Make    MadeIn      Sales

GM      2005          100
GM      2006         1200
GM      2007          600             

What I have to do is work out the greatest increase in Sales between 2005 and 2007 and display this value and the Make

I think I have the answer to the increase but cannot display the 'Make' to go along side the increase in sales (growth)

This is what I have so far:

   select max(growth)
      from (
          select make, max(sales) - min(sales) as growth 
          from cars group by make) as carsales,cars;

I need the result to show:

Make     Growth

GM       1100

The results of your query come from your first select statement

I would show you but I don't want to give to much away, you'll learn more that way.

Note that the query you have now will give you the total growth (or loss). It won't give you the growth in one year.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM