2,596
社区成员
发帖
与我相关
我的任务
分享
--表B_CallNo 数据--
ID CtrlNo CallNo Lib
1 101 TP393 1
2 101 TP393 2
--表B_Barcode数据--
ID Barcode CtrlNo
1 A0001 101
2 A0002 101
3 A0003 101
4 A0004 101
用查询语句:
select substring( CallNo , 1 ,2) as class,count(Barcode) as Total
from B_Barcode a , B_CallNo b
where a.CtrlNo = b.CtrlNo
group by substring( CallNo , 1 ,2)
order by Total desc
查询得结果:
class Total
---- -----
TP 8
select substring( CallNo , 1 ,2 ) as class , count(Barcode) as Total
from (select distinct CtrlNo , CallNo from B_CallNo ) a , B_Barcode b
where a.CtrlNo = b.CtrlNo
group by substring( CallNo , 1 ,2)
order by Total desc