Mysql与复杂的子查询连接
我有两个select语句,我想通过它们的公共列连接它们: 第一个问题: 选择self_code作为“DSLAM_code”,按self_code从obj_端口组中将self_code计数为“Registered” 产出: 第二个问题: 选择子字符串\u indexdslamportid:,1作为DSLAM\u代码, 将子字符串_indexdslamportid:,1从radacct中计算为活动,其中 类似于dslamportid的“%:%”按子字符串\u indexdslamportid:,1分组 产出: 我尝试使用以下查询连接两个输出表失败: 选择A.self\u代码作为“DSLAM\u代码”,选择A.countself\u代码作为“已注册” 从obj_端口A组按F.self_代码左连接选择 子字符串_indexdslamportid:,1作为dslam, countsubstring_indexdslamportid:,1作为来自radacct的计数,其中 类似于“%:%”的dslamportid按子字符串\u indexdslamportid,1 B分组 在A.self_code=B.dslam上 我发现语法错误: 错误代码:1064。您的SQL语法有错误;检查 与右边的MySQL服务器版本相对应的手册 使用“左联接选择”的语法 子字符串_indexdslamportid,:,1作为dslam,在第行处计数子字符串 二,Mysql与复杂的子查询连接,mysql,join,subquery,Mysql,Join,Subquery,我有两个select语句,我想通过它们的公共列连接它们: 第一个问题: 选择self_code作为“DSLAM_code”,按self_code从obj_端口组中将self_code计数为“Registered” 产出: 第二个问题: 选择子字符串\u indexdslamportid:,1作为DSLAM\u代码, 将子字符串_indexdslamportid:,1从radacct中计算为活动,其中 类似于dslamportid的“%:%”按子字符串\u indexdslamportid:,1分
提前感谢亲爱的社区 好的,我找到了一个方法: 从选择自身代码中选择a.DSLAM\U代码、a.已注册、b.活动 作为“DSLAM_代码”,将自身_代码从obj_端口组计数为“已注册” 通过自编码左连接选择 子字符串\u indexdslamportid:,1作为DSLAM\u代码, 将子字符串_indexdslamportid:,1从radacct中计算为活动,其中 类似于“%:%”的dslamportid按子字符串\u indexdslamportid,1 b分组 在a.dslam_码上=b.dslam_码
join语句之前不能有group by语句。
+------------+------------+
| DSLAM_code | Registered |
+------------+------------+
| 10000 | 317 |
| 10001 | 344 |
| 10002 | 93 |
+------------+------------+
+------------+--------+
| DSLAM_code | Active |
+------------+--------+
| 10000 | 265 |
| 10001 | 299 |
| 10002 | 83 |
+------------+--------+