如题,直入正题:
2张表 
A

id 
name 
content

b

bid 
id 
name 
content

现在要统计在b表中id 出现最多的 并且只要返回一个id,高人指点下,没思路阿。

解决方案 »

  1.   

    select id, count(*) from b group by id
    --这样?
      

  2.   

    select id from b group by id order by count(*) desc
      

  3.   


    --取一个id就加top 1
    select top 1 id from b group by id order by count(*) desc
      

  4.   

    select top 1 id, count(*) from b group by id order by count(*) desc
    --这样?
      

  5.   


    嗯,谢谢。求解释。现在还不会用group by ,
      

  6.   

    select top 1 with ties id 
    from b 
    group by id 
    order by count(*) desc
      

  7.   


    select top 1 with ties sku_id from ecs_goods_gallery group by sku_id order by count(*) desc错误码: 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 '1 with ties sku_id from ecs_goods_gallery group by sku_id order by count(*) desc' at line 1
      

  8.   


    select id, count(*) from b group by id order by 2分组查询 每一个id一个组  count(*) 表示同一个id中用多少行数据