select isbn , min(书名) , count(*) 数量 from tb group by isbn select isbn , max(书名) , count(*) 数量 from tb group by isbn
--第一本 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
我找出来了,不能用count(*) 数量,这好像是对条数相加,而不是对字段内数据相加。这样是对的 SELECT ISBN, Min(书名), Sum(册数) AS 册数 FROM A GROUP BY A.ISBN;
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])
SELECT ISBN, Min(书名), Sum(册数) AS 册数 FROM A GROUP BY A.ISBN;
select isbn , max(书名) , count(*) 数量 from tb group by isbn
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
SELECT ISBN, Min(书名), Sum(册数) AS 册数
FROM A
GROUP BY A.ISBN;
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])
SELECT ISBN, Min(书名), Sum(册数) AS 册数
FROM A
GROUP BY A.ISBN;