简单的SQL语句出错,请各位老大指点
表1 resume_cnv
id
username
sex
....
表2 myresume
Coname
ResumeID
....
我想实现的功能是:
a) 列出表1所有记录
b) 列出表2中ResumeID = 表1.ID 的记录数,如果没有记录,则输出0
我写的SQL总是报前缀 "b "错误,这是为什么?
SELECT b.*, a.ucuserid AS Expr1
FROM dbo.resume_cnv b LEFT OUTER JOIN
(SELECT COUNT(*) AS ss
FROM myresume
WHERE resumeid = b.id
GROUP BY ucuserid) a ON b.id = a.resumeid
------解决方案--------------------a ON b.id = a.resumeid
你的a表没有resumeid字段吧?
我想你是这个意思吧?
SELECT distinct b.*,(SELECT COUNT(*) FROM myresume WHERE resumeid = b.id) as ucuserid
FROM dbo.resume_cnv b
------解决方案--------------------兄弟啊,你的子查询 a 里根本没有 resumeid 这一列你怎么引用啊?
SELECT ucuserid, COUNT(*) AS ss
FROM myresume
WHERE resumeid = b.id
GROUP BY ucuserid
这个子查询你只能引用两列,a.ucuserid,a.ss,上边有个哥们儿已经说过了。难道是你打错了?