原表要求结果
目的:表a中isbn相同的书有很多,但是各书名不同,我想要统计出isbn相同的书的总册数,并且保留第一条书名

解决方案 »

  1.   

    select isbn , min(书名) , count(*) 数量 from tb group by isbn
    select isbn , max(书名) , count(*) 数量 from tb group by isbn
      

  2.   

    --第一本
    select n.* , m.数量 from
    (select isbn , count(*) 数量 from tb group by isbn) m,
    (select a.* from tb a where 书名 = (select top 1 书名 from tb where isbn = a.isbn) ) n 
    where m.isbn = n.isbn--书名最小的一本
    select isbn , min(书名) , count(*) 数量 from tb group by isbn --书名最大的一本
    select isbn , max(书名) , count(*) 数量 from tb group by isbn 
      

  3.   

    我找出来了,不能用count(*) 数量,这好像是对条数相加,而不是对字段内数据相加。这样是对的
    SELECT ISBN, Min(书名), Sum(册数) AS 册数
    FROM A
    GROUP BY A.ISBN;
      

  4.   


    select [ISBN],[总册数],[书名]
    from
    (
      select [ISBN],sum([册数])[总册数] from a
      group by [ISBN]
    )A
    where A.[书名] in(select top 1 [书名] from a where a.[ISBN]=A.[ISBN])
      

  5.   


    SELECT ISBN, Min(书名), Sum(册数) AS 册数
    FROM A
    GROUP BY A.ISBN;
      

  6.   

    谢谢dawugui guxiaoshi !!