能不能单纯通过SQL实现...
main表  两个字段id、team
能不能按team中某数据出现次数由高到低排序并列出出现的次数例如id | team | count
-----------------------
2  |team2 |  10
1  |team1 |    8
3  |team3 |    5

解决方案 »

  1.   

    select id,team,(select count(1) [count] from main b inner join a on a.id=b.id group by team )
    from main a
    order by [count] desc 
      

  2.   

    a和b是什么
    原谅新手SQL不太会
      

  3.   

    MySQL 返回: #1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select count( 1 ) [ count ] from main b inner join a on a.id =
      

  4.   

    是为表起的别名,只在当前语句内有效,例如 a.id  你可以写成 main.id 
    但是当from 子句里有多个 main表时,就必须指定别名 这样数据库才可以区分两个表
      

  5.   

    晕,mysql你来SQLServer专区发干嘛?又不说清楚
      

  6.   

    http://topic.csdn.net/u/20121011/23/3bd1cf03-8124-40cf-a03d-5cf34a601987.html?99628到这接分吧
      

  7.   

    mysql 不会,已经回复那个贴了
      

  8.   

    drop table main
    create table main(id int identity,team varchar(10))
    go
    insert into main select 'term1'
    GO 3
    insert into main select 'term2'
    GO 4
    insert into main select 'term3'
    GO 5--select id,team,(select count(1) [count] from main b where a.team=b.team group by team )[count]
    from main a
    order by [count] desc 我不信你这个就不用结分
      

  9.   

    结贴吧。丢mysql问呗,或者自己改一下,mysql语法不会,我的写法有点问题。给磊子分吧
      

  10.   

    select a.id,a.team,b.[count]
    from main a,(select team ,count(1) [count] from main b group by team ) b
    where a.team=b.team 
    order by b.[count] desc 
      

  11.   

    select id,team,count(*)over(partition by team)[count]
    from main a
    order by [count] desc 
      

  12.   

    mysql的是这样的SELECT `team`,COUNT(*) AS count 
    FROM `main` 
    GROUP BY `team`,`ip` 
    ORDER BY count DESC 孤陋寡闻.一直以为SQL语句放哪都差不多~~