解决方案 »
- 存储过程 游标 问题求助%>_<%
- 想取相同名称的记录中最近的一条
- mysql插入问题
- 关于数据库where in()和left join 联合查询的性能问题。。
- ERROR 126 (HY000): Incorrect key file for table '/tmp/#sql_6f81_0.MYI'; try to r
- 遇到mysql case when 问题
- 自己整合的lamp中mysql查询时间 比 xampp中的mysql 慢了一倍左右
- 求一SQL
- windows下mysql怎样修改端口
- 一个很弱智的问题,message表应该怎样设计
- 求一条SQL语句
- mysql定时执行存储过程问题
where a.id = b1.aid and b1.id = c.bid and a.id = b2.aid and b2.id = d.bid
这种查询和JOIN合计出来的结果都会存在重复的合计
-- ----------------------------
-- Table structure for `a`
-- ----------------------------
DROP TABLE IF EXISTS `a`;
CREATE TABLE `a` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;-- ----------------------------
-- Records of a
-- ----------------------------
INSERT INTO `a` VALUES ('1', 'aaaa');
INSERT INTO `a` VALUES ('2', 'bbbb');
INSERT INTO `a` VALUES ('3', 'ccccc');-- ----------------------------
-- Table structure for `b`
-- ----------------------------
DROP TABLE IF EXISTS `b`;
CREATE TABLE `b` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`aid` int(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;-- ----------------------------
-- Records of b
-- ----------------------------
INSERT INTO `b` VALUES ('1', '1');
INSERT INTO `b` VALUES ('2', '2');
INSERT INTO `b` VALUES ('3', '3');-- ----------------------------
-- Table structure for `c`
-- ----------------------------
DROP TABLE IF EXISTS `c`;
CREATE TABLE `c` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`bid` int(10) DEFAULT NULL,
`num` int(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;-- ----------------------------
-- Records of c
-- ----------------------------
INSERT INTO `c` VALUES ('1', '1', '5');
INSERT INTO `c` VALUES ('2', '2', '1');
INSERT INTO `c` VALUES ('3', '3', '2');
INSERT INTO `c` VALUES ('4', '1', '4');
INSERT INTO `c` VALUES ('5', '3', '2');-- ----------------------------
-- Table structure for `d`
-- ----------------------------
DROP TABLE IF EXISTS `d`;
CREATE TABLE `d` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`bid` int(10) DEFAULT NULL,
`num` int(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;-- ----------------------------
-- Records of d
-- ----------------------------
INSERT INTO `d` VALUES ('1', '1', '1');
INSERT INTO `d` VALUES ('2', '3', '2');
INSERT INTO `d` VALUES ('3', '1', '1');
INSERT INTO `d` VALUES ('4', '2', '4');
INSERT INTO `d` VALUES ('5', '2', '1');试一下这个表结构。