sql 多表关联查询,看下这句sql哪里错了,高手进,在线等!!!!
SELECT*FROMaaaast1JOIN((SELECTcount(*)frombbbwheresid=t1.sid)asjieguo)ast2WHEREt2.jie...
SELECT * FROM aaa as t1 JOIN ((SELECT count(*) from bbb where sid=t1.sid) as jieguo) as t2 WHERE t2.jieguo > 0
展开
3个回答
展开全部
你语法就错了。 你的T1表 和T2表 关系呢?下面是语法。 你的on后面关系没写,且 你第二张表只有汇总字段 ,这怎么能关联!
select * from T1 join T2 on T1.code=T2.code
改成如下写法
SELECT * FROM aaa as t1 JOIN ((SELECT count(*) as jieguo,sid from bbb Group by sid) as jieguo) as t2 on T1.sid=t2.sid WHERE t2.jieguo > 0
select * from T1 join T2 on T1.code=T2.code
改成如下写法
SELECT * FROM aaa as t1 JOIN ((SELECT count(*) as jieguo,sid from bbb Group by sid) as jieguo) as t2 on T1.sid=t2.sid WHERE t2.jieguo > 0
追问
也报错啊
追答
SELECT * FROM aaa as t1 JOIN ((SELECT count(*) as jieguo,sid from bbb Group by sid) as jieguo) as t2 on T1.sid=t2.sid WHERE t2.jieguo > 0
逗号问题
展开全部
jieguo=t2=count(*)是一个数字吧
追问
是啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-11-30 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
把 sid=t1.sid改为jieguo.sid=t1.sid,如下:
SELECT * FROM aaa as t1 JOIN ((SELECT count(*) from bbb where jieguo.sid=t1.sid) as jieguo) as t2 WHERE t2.jieguo > 0;
SELECT * FROM aaa as t1 JOIN ((SELECT count(*) from bbb where jieguo.sid=t1.sid) as jieguo) as t2 WHERE t2.jieguo > 0;
追问
不行啊,还是报错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询