左连接
时间:2011-09-29
来源:互联网
这个是月查询的,但是我查询出来的结果集有重复项,左连接应该是已左表为准右表有符合条件的数据会查询出来,没有就用null显示,我左表有49条数据,右表有5条数据,都是4月的,左连接查询出来应该是49条,但是我查询出来的是245条,咋回事?
作者: liuchengbjaccp 发布时间: 2011-09-29
假如你两个表有2个字段要做连接的,你只做了一个,那么左表的每一行记录都要和右表的记录连接起来,那么总记录数就是左表数量*右表数量
作者: jimmylin040 发布时间: 2011-09-29
select * from algaehistorydata a left join monthreportdata m on a.sitecode=m.sitecode and a.rmonth=m.rmonth where a.sitecode = '20029-71200002' and a.rmonth = '4' group by a.recordtime
作者: lzd_83 发布时间: 2011-09-29
作者: liuchengbjaccp 发布时间: 2011-09-29
我只是查询2张表中俩字段想匹配的啊,一个是sitecode一个是rmonth,,条件都写了,还得需要写个?
select * from algaehistorydata a left join monthreportdata m on a.sitecode=m.sitecode and a.rmonth=m.rmonth where a.sitecode = '20029-71200002' and a.rmonth = '4' group by a.recordtime
从语句来看,没什么错误,应该是条件的问题.漏掉了什么?
作者: dawugui 发布时间: 2011-09-29
右表,monthreportdata中有sitecode,recordtime,rmonth等字段。我想查询出rmonth是4,sitecode是'20029-71200002' 的结果集,并且是左连接的。
作者: liuchengbjaccp 发布时间: 2011-09-29
你把left join 换成inner join 看看是什么情况?
select * from algaehistorydata a left join monthreportdata m on a.sitecode=m.sitecode and a.rmonth=m.rmonth where a.sitecode = '20029-71200002' and a.rmonth = '4' group by a.recordtime
我猜测你是碰到一对多了.
作者: dawugui 发布时间: 2011-09-29
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28