请教一个查询的SQL,弄了半天弄不出来。来请教高手
- SQL code
tbaid Savepath1, xxx 2, xxx 3, xxx 4, xxx 5, xxx tbbid,aid11,112,413,414,5--想要的结果id, Savepath,count(指tbb的记录条数)1, xxx ,1 2, xxx ,0 3, xxx ,0 4, xxx ,2 5, xxx ,1 (下面的总出错因为Savepath是TEXT型,总是出错:不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符错误)select a.id,a.savepath,count(b.aid) from tba ainner join tbb b on b.aid=a.idgroup by a.id,a.savepath,b.count
------解决方案--------------------
- SQL code
create table tba(id int,Savepath text)insert into tba select 1, 'xxx' insert into tba select 2, 'xxx' insert into tba select 3, 'xxx' insert into tba select 4, 'xxx' insert into tba select 5, 'xxx' create table tbb(id int,aid int)insert into tbb select 11,1insert into tbb select 12,4insert into tbb select 13,4insert into tbb select 14,5goselect *,(select count(*) from tbb where aid=a.id)ctfrom tba aid Savepath ct----------- ----------------- -----------1 xxx 12 xxx 03 xxx 04 xxx 25 xxx 1(5 行受影响)godrop table tba,tbb
------解决方案--------------------
------解决方案--------------------