这个SQL有什么问题吗?
我确信这是我忽略的非常简单的事情,但 MS SQL 对我来说是新的——不过我(或者至少认为我是)对基本的 MySql 相当满意。
SELECT l.link_id, l.link_allcount, d.desc_id, d.desc_count, d.desc_text, h.hour_17, dl.day_19
FROM lnktrk_links AS l, lnktrk_hourly AS h, lnktrk_daily AS dl
LEFT JOIN lnktrk_descriptions AS d ON l.link_id = d.link_id
WHERE l.link_id = h.link_id AND l.link_id = dl.link_id AND l.link_is_click = 1
我得到的错误是:
'The multi-part identifier "l.link_id" could not be bound.
但是 l.link_id 肯定存在。以下没有连接的查询按预期工作:
SELECT l.link_id, l.link_allcount, d.desc_id, d.desc_count, d.desc_text, h.hour_17, dl.day_19
FROM lnktrk_links AS l, lnktrk_hourly AS h, lnktrk_daily AS dl, lnktrk_descriptions AS d
WHERE l.link_id = h.link_id AND l.link_id = dl.link_id AND d.link_id = l.link_id AND l.link_is_click = 1
I'm sure this is something really simple that I'm overlooking, but MS SQL is new to me -- I am (or at least thought I was) fairly comfortable with basic MySql though.
SELECT l.link_id, l.link_allcount, d.desc_id, d.desc_count, d.desc_text, h.hour_17, dl.day_19
FROM lnktrk_links AS l, lnktrk_hourly AS h, lnktrk_daily AS dl
LEFT JOIN lnktrk_descriptions AS d ON l.link_id = d.link_id
WHERE l.link_id = h.link_id AND l.link_id = dl.link_id AND l.link_is_click = 1
The error I get is:
'The multi-part identifier "l.link_id" could not be bound.
However l.link_id definitely exists. The following query without the join works as expected:
SELECT l.link_id, l.link_allcount, d.desc_id, d.desc_count, d.desc_text, h.hour_17, dl.day_19
FROM lnktrk_links AS l, lnktrk_hourly AS h, lnktrk_daily AS dl, lnktrk_descriptions AS d
WHERE l.link_id = h.link_id AND l.link_id = dl.link_id AND d.link_id = l.link_id AND l.link_is_click = 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
try this :
我认为语法
比逗号分隔的子句绑定得更紧密,因此该部分中没有 l
您所拥有的内容分组为:
I think it is that the syntax binds
more tightly than the comma-separated clauses so you don't have an l in that part
What you have is grouped as:
该
LEFT JOIN
正在将lnktrk_daily AS dl
与lnktrk_descriptions AS d
连接起来 - 这些都不被称为l
,所以< em>在JOIN
的ON
子句的上下文中,l
没有任何意义。看起来目前您正在使用“交叉连接加
WHERE
子句”样式,而不是“带有ON
子句的内连接”样式。如果您切换到后者,那么l
应该在整个FROM
子句中有意义。That
LEFT JOIN
is joininglnktrk_daily AS dl
withlnktrk_descriptions AS d
- neither of these are calledl
, so in the context of thatJOIN
sON
clause,l
doesn't mean anything.It looks like at the moment you are using the 'cross join plus
WHERE
clauses' style rather than 'inner joins withON
clauses' style. If you switch to the latter thenl
should have meaning across the wholeFROM
clause.你应该加入它们 - 而不是使用 FROM
试试这个
You should join them all - instead of using FROM
Try this