一个表table1有两列:name,car。
例如:
张三,奔驰
张三,宝马
李四,宝马我要选择人名和拥有的车的数量,以上例子的结果为:
张三,2
李四,1sql语句怎么写?
谢谢各位!

解决方案 »

  1.   

    select name,count(1) as num from table1 group by name
      

  2.   

    select name,count(*) 
    from 表
    group by name
      

  3.   

    select name,count(*) as num
    from 表
    group by name
    order by count(*) desc
      

  4.   

    select name,count(*)
    from tb
    group by name
      

  5.   

    select name,sum(car) from table1 group by name
      

  6.   


    select name,count(1) as num
    from 表
    group by name
    order by count(1) desc效率会高点
      

  7.   

    select name,count(1) as num from table1 group by name
      

  8.   

    一个表table1有两列:name,car,age 
    例如: 
    张三,奔驰,30 
    张三,宝马,30 
    李四,宝马,40 我要选择人名和拥有的车的数量,并且age大于30,以上例子的结果为: 
    李四,1 sql语句怎么写? 
    谢谢各位!
      

  9.   


    select a.*
    ,(select count(1) from table1 b where a.name=b.name) 
    (select distinct name 
    from table1 a
    where age>30) a
      

  10.   

    select name, count(*) from table1 where age>30 group by name