求各位高手一个SQL语句的写法。急等。。。。。(50分)

Y

yym

Unregistered / Unconfirmed
GUEST, unregistred user!
数据库苛字段AA内容为:
XX000
XX000
XX001
XX001
XX001
XX002
XX003
XX004
要求统计出后三位相同的分类个数:
如上面的后三位结果为 000,001,002,003,004 结果相加值为5条,我要的就是这个数字5
不要告诉我用如下语句:
select count(substring(aa,3,3)) number from tmptabel
group by substring(aa,3,3) 或此句少掉,这肯定不对,列出的为多记录。我就要单记录
 
select count(distinct(substring(aa,3,3))) number from tmptabel
 
那我什么也不告诉你了
 
分數太少了[:D][:D][:D]
 
Select Count(*)
From (Select distinct substring(aa,3,3) From tmptable1) AA
 
分数少了点,如果你认为通了多给我点呀:)
这是是用SQLSERVER的NORTHWIND数据库调试的,意思是查出不同供应商的产品数量:
select count(*) from products tb1, (select f1 from
(Select distinct (SupplierID) f1 From products )tb2 group by tb2.f1) tb3
where tb1.SupplierID=tb3.f1
group by tb1.SupplierID

对你的:把SupplierID改为:substring(aa,3,3),更换表名称就可以:
select count(*)
from (select substring(AA,1,1) f2 from tmptabel) tb1,
(select f1 from (Select distinct (substring(AA,1,1)) f1 From tmptabel)tb2 group by tb2.f1) tb3
where tb1.f2=tb3.f1
group by tb1.f2


如果调不通参考:
select count(*) from (select substring(productName,1,1) f2 from products) tb1,
(select f1 from
(Select distinct (substring(productName,1,1)) f1 From products )tb2 group by tb2.f1) tb3
where tb1.f2=tb3.f1
group by tb1.f2

 
the answer is:
[8D][8D][8D][8D][8D][8D][8D]

select distinct aa ,count(aa) from tmptabel group by aa


[8D][8D][8D][8D][8D][8D][8D]
 
忘了,在SQL BUILDER 中就有。
 
这么简单的问题,还是多看看帮助吧!
 
多人接受答案了。
 
顶部