我创建了3个表如下
表格Student1:
id status amount Name date
1 0 4500 ram 04/02/2012
2 0 2000 shyam 05/09/2013
4 0 1500 ghanshyam 08/11/2014
表格Student2:
id status amount Name date
3 0 4500 gopal 04/02/2012
2 0 8000 radheshyam 15/11/2013
4 1 1500 ghanshyam 18/10/2015
表格Student3:
id status amount Name date
1 1 4500 ram 04/02/2012
2 0 6500 radhe 11/11/2014
3 1 4500 gopal 04/02/2012
例外结果条件:
1)选择具有唯一" id"的记录。从3个表组合。
2)更新字段"日期"如果相同记录的状态= 1,则具有相同记录的相同记录,3个表中的任何一个中的金额。
3)如果将3个表与相同的" id"组合后,如果是2个或2个以上的记录但其他字段不同(即相同的ID,但名称,金额,日期不同)然后将它们添加到最终结果,但我将1,111,111附加到它们。
预期的最终结果:
id status amount Name date
1 1 4500 ram 04/02/2012
2 0 2000 shyam 05/09/2013
21 0 8000 radheshyam 15/11/2013
211 0 6500 radhe 11/11/2014
3 1 4500 gopal 04/02/2012
4 1 1500 ghanshyam 18/10/2015
Sql Fiddle
CREATE TABLE Student1
(`id` int,`status` int,`amount` int , `Name` varchar(10), `date` varchar(55))
;
INSERT INTO Student1
(`id`,`status`,`amount`, `Name`, `date`)
VALUES
(1,0,4500, 'ram', '04/02/2012'),
(2,0,2000, 'shyam', '05/09/2013'),
(4,0,1500, 'ghanshyam', '08/11/2014')
;
CREATE TABLE Student2
(`id` int,`status` int,`amount` int , `Name` varchar(10), `date` varchar(55))
;
INSERT INTO Student2
(`id`,`status`,`amount`, `Name`, `date`)
VALUES
(3,0,4500, 'gopal', '04/02/2012'),
(2,0,8000, 'radheshyam', '15/11/2013'),
(4,1,1500, 'ghanshyam', '18/10/2015')
;
CREATE TABLE Student3
(`id` int,`status` int,`amount` int , `Name` varchar(10), `date` varchar(55))
;
INSERT INTO Student3
(`id`,`status`,`amount`, `Name`, `date`)
VALUES
(1,1,4500, 'ram', '04/02/2012'),
(2,0,6500, 'radhe', '11/11/2014'),
(3,1,4500, 'ghanshyam', '04/02/2012')
;
查询:
SELECT * FROM Student1
FULL OUTER JOIN Student2
ON Student1.Name = Student2.Name
错误:
check the manual that corresponds to your MySQL server version for the right syntax to use near 'OUTER JOIN Student2 ON Student1.Name = Student2.Name' at line 2
答案 0 :(得分:2)
这只是这三张桌子之间的联盟。