另一道sql有关问题,高人请进

另一道sql问题,高人请进!

4. Sample tables (company_id RK companies.id):

Companies

id company

1 …

2 …

3 …

Locations

id company_id location revision

1 1 … 1

2 2 … 1

3 1 … 2

4 1 … 3

5 2 … 2

6 1 … 4

Task: write an SQL query to select values from the following columns (companies.company, locations.location) where locations.revision value will be the highest for each company


SQL code

select c.company,l.location
from ( Companies c inner join (select company_id,max(revision) as maxrevision
from Locations) m on c.id = m.company_id) inner join Locations l on m.maxrevision=l.revision and m.company_id=l.company_id


                        
  
  
                    
另一道sql有关问题,高人请进

相关文章:

你感兴趣的文章:

标签云: