相关的 mysql 子查询
您好,我想从子查询内的主查询获取变量的值
SELECT t1.*,sq.*,count(distinct(t4.col1)) as count,
FROM t1 LEFT OUTER JOIN(
SELECT t2.col1,
t2.col2,
t2.col3
FROM t2
WHERE t2.col1=t1.col1
ORDER BY t2.col2 DESC, t2.col1 DESC
) as sq
ON sq.col1=t1.col1
LEFT OUTER JOIN t3 ON t3.col1=t1.col4
LEFT OUTER JOIN t4 ON t4.col1=t1.col4
WHERE t3.col2=x
GROUP BY t1.col3
LIMIT 15
当我将其加入同一列时,如何获取子查询 sq 内变量 t1.col1 的值?
HI i want to get the value of the variable from the main query inside the sub query
SELECT t1.*,sq.*,count(distinct(t4.col1)) as count,
FROM t1 LEFT OUTER JOIN(
SELECT t2.col1,
t2.col2,
t2.col3
FROM t2
WHERE t2.col1=t1.col1
ORDER BY t2.col2 DESC, t2.col1 DESC
) as sq
ON sq.col1=t1.col1
LEFT OUTER JOIN t3 ON t3.col1=t1.col4
LEFT OUTER JOIN t4 ON t4.col1=t1.col4
WHERE t3.col2=x
GROUP BY t1.col3
LIMIT 15
How do i get the value of the variable t1.col1 inside the subquery sq when I am joining it on the same column??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能,但以下应该返回与您发布的查询相同的结果。
注意:您发布的原始查询包含一些语法错误。
You can't but following should return equivalent results as the query you've posted.
Note: the original query you've posted contains a few syntax errors.