SQL选择最大值

时间:2015-11-02 11:06:15

标签: mysql sql

我有如下查询:

import requests,re
from  bs4  import  BeautifulSoup

url ="http://www.sportsbet.com.au/betting/american-football"
r = requests.get(url)
soup = BeautifulSoup(r.content,'lxml')

#get Sport

g_data = soup.find_all("div", {"class": "accordion-main"})

for items in g_data:
     sport = items.findAll('span', {'class': 'market_title'})[0]
     print sport.text

#get odds and teams

g_data = soup.find_all("div", {"class": "accordion-body"})

for items in g_data:
     teama = items.findAll('span', {'class': 'team-name ib'})[0]
     teamb = items.findAll('span', {'class': 'team-name ib'})[3]
     pricea = items.findAll('span')[1]
     priceb = items.findAll('span')[7]
     print teama.text + teamb.text + pricea.text.strip() + priceb.text.strip()

#get game and time

g_data = soup.find_all("div", {"class": "market-name cfix"})

for items in g_data:
     game = items.findAll('a', {'class': 'link'})[0]
     time = items.findAll('span', {'class': 'start-time timezone_time'})[0]
     print game.text + time.text

#get date


g_data = soup.find_all("div", {"class": "bettypes-header cfix"})

for items in g_data:
     game_date = items.findAll('span', {'class': 'timezone_day_date date'})[0]
     print game_date.text

答案如下:

NFL Matches
Indianapolis ColtsCarolina Panthers3.331.35
Cleveland BrownsCincinnati Bengals5.651.16
Miami DolphinsBuffalo Bills2.301.65
Washington RedskinsNew England Patriots10.501.06
Oakland RaidersPittsburgh Steelers2.941.43
St. Louis RamsMinnesota Vikings2.251.68
Atlanta FalconsSan Francisco 49ers1.502.69
New York GiantsTampa Bay Buccaneers1.802.06
Philadelphia EaglesDallas Cowboys1.782.09
Chicago BearsSan Diego Chargers2.711.49
Indianapolis Colts At Carolina Panthers12:30
Cleveland Browns At Cincinnati Bengals12:25
Miami Dolphins At Buffalo Bills05:00
Washington Redskins At New England Patriots05:00
Oakland Raiders At Pittsburgh Steelers05:00
St. Louis Rams At Minnesota Vikings05:00
Atlanta Falcons At San Francisco 49ers08:05
New York Giants At Tampa Bay Buccaneers08:05
Philadelphia Eagles At Dallas Cowboys12:30
Chicago Bears At San Diego Chargers12:30
Tuesday 03/11/2015
Friday 06/11/2015
Monday 09/11/2015
Tuesday 10/11/2015

来自DB 55是最长时间的正确答案。但布莱克不工作55个小时,这是另一个名叫格兰特的人。似乎我有一个与彼此无关的答案。我该怎么办才能得到:

“格兰特55”作为答案。

2 个答案:

答案 0 :(得分:1)

Select E.LName, SUM(Hours) as HOURS    
From WORKS_ON W    
   JOin EMPLOYEE E on E.SSN=W.ESSN    
group by E.LName
ORDER BY HOURS desc
limit 1

答案 1 :(得分:0)

我假设在E表中有不同的LName,SSN

Select 
    E.LName
    ,SUM(Hours) as HOURS    
From 
    WORKS_ON W    
    JOin EMPLOYEE E on E.SSN=W.ESSN 
GROUP BY
    E.SSN
    ,E.LName   
ORDER BY 
    E.LName

您可能希望根据您的要求更改order by子句。