SQL 的问题,在线急等 (使用count统计某一栏出现的次数)

来源:百度知道 编辑:UC知道 时间:2024/06/20 00:52:39
有这样一张表A,包含2栏,厂商和产品

Vender Product
Dell Server
Dell NoteBook
Dell DeskTop
Nokia Mobile

现在希望通过一个SQL语句得到这样一张表, count是厂商对应产品的数量

Vender Count Product
Dell 3 Server
Dell 3 NoteBook
Dell 3 DeskTop
Nokia 1 Mobile

分数不多,都送了,希望的到各位的指导
格式有点乱,重新整理一下

有这样一张表A,包含2栏,厂商和产品

Vender--Product
Dell----Server
Dell----NoteBook
Dell----DeskTop
Nokia---Mobile

现在希望通过一个SQL语句得到这样一张表, count是厂商对应产品的数量

Vender--Count--Product
Dell----3------Server
Dell----3------NoteBook
Dell----3------DeskTop
Nokia---1------Mobile

分数不多,都送了,希望的到各位的指导

我用的是SQL server,前面3个回答都不会得到我想要的结论
得到的表是这样的
Dell---3
Nokia--1

我希望这张表能和表A Join 在一起,也就是 由表A查询产生的表 Join 表A,
我猜SQL语句大概是这样的
Select vender, count, product from A join (select vender as vender2, count(product) as count from A) on A.product=?.product
我不知道?的地方要怎么写

呵呵 。 两个人各答对了一半。
应该是这么写吧 。
select venderm,count(product) as 'count' ,product
from table group by vender,product
如果想创建一个新表
select vender,count(product) as 'count' ,product
into newtable from table group by vender,product
不过如果你用access不知道有没有这个功能
明白你什么意思了。你看看这么写行吗?
select vender,
d.counts ,product
from a join (select product as 'x',count(product) as 'counts' from a group by product) as d
on a.product=d.x

试试看这样 ...?

SELECT *,COUNT(Product) AS yanzi FROM tableA GROUP BY Vender,Product

select Vender,count(*),Product into 新表名 from A group by Vender