现有一表Products,内有二个字段,分别是:id,Lname例表中数据如下:
id        Lname 
1          aa    
2          aa   
3          bb    
4          cc     
5          cc     
6          aa    查询结果:
产品数量统计: aa 有 3台 bb 有1台 cc有两台
请问SQL语句怎么样?数据库是ACCESS

解决方案 »

  1.   


    select Lname,count(1) from tb group by Lname
      

  2.   

    SELECT LANME ,COUNT(*) AS NUM FROM TB GROUP BY LNAME
      

  3.   

    select laname,count(1) as 数量  from tb group by lname 
      

  4.   

    还不行 哪位能给出完整的代码 并解释一下SQL语句的含义
      

  5.   

    /*
    -- Author:SQL77--RICHIE 
    -- Version:V1.001  Date:2008-05-15--转Flystone*/-- Test Data: TB
    If object_id('TB') is not null 
        Drop table TB
    Go
    Create table TB(id int,Lname varchar(2))
    Go
    Insert into TB
    select 1,'aa' union all
    select 2,'aa' union all
    select 3,'bb' union all
    select 4,'cc' union all
    select 5,'cc' union all
    select 6,'aa' 
    Go
    --Start
    Select lname,count(*)as num  from TB group by lname
    --Result:
    /*(所影响的行数为 6 行)lname num         
    ----- ----------- 
    aa    3
    bb    1
    cc    2(所影响的行数为 3 行)
    */
    --End 
      

  6.   

    只出现 aa       bb         cc没有数量
      

  7.   

    ASP里用的 SQL77兄弟你这是哪里调试的  麻烦兄弟给个ASP中用的完整代码 谢谢
      

  8.   

    ASP中不懂的,呵呵,这是SQL中的,ASP中你不绑定不会有吧
      

  9.   

    我的代码是这样写的:
    <!--#include file="conn.asp"--><% 
    dim rs,num
    set rs = server.createobject("adodb.recordset")
    sql="SELECT Lname,count(*) as num from Products GROUP BY Lname"
    rs.open sql,conn,1,1
    if rs.BOF then
      response.write "<tr><td colspan='8' width='100%' height='50' align='center'>无相关内容!</td>"
    end iffor i=1 to 10
    if rs.EOF or rs.BOF then exit for
    %>
    <table>
    <tr bgcolor="#F2F2F2" >
         <td height="26" bgcolor="#BAD1FC"><strong>数量统计:<%= rs("Lname") %>&nbsp;&nbsp;<%= num %></strong></td>
    </tr>
    </table>
    <%
    rs.movenext
    next
    %>