CREATE TABLE `table1` (
`Nameid` int(6) NOT NULL,
`name` varchar(20) default NULL,
`amount` double default NULL,
PRIMARY KEY (`Nameid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `table1` (`Nameid`, `name`, `amount`) VALUES
(1, 'chan', 2000),
(2, 'john', 3000),
(3, 'james', 2000);
CREATE TABLE `table2` (
`Pid` int(5) NOT NULL auto_increment,
`Nameid` int(5) default NULL,
`product` varchar(20) default NULL,
`price` double default NULL,
PRIMARY KEY (`Pid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
INSERT INTO `table2` (`Pid`, `Nameid`, `product`, `price`) VALUES
(1, 3, 'ghee', 400),
(2, 2, 'dhal', 100),
(3, 1, 'chenna', 150);
CREATE TABLE `table3` (
`Sid` int(5) NOT NULL,
`Nameid` int(5) default NULL,
`expence` double default NULL,
`place` varchar(25) default NULL,
PRIMARY KEY (`Sid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `table3` (`Sid`, `Nameid`, `expence`, `place`) VALUES
(1, 2, 280, 'Ny'),
(2, 1, 500, 'At'),
(3, 3, 600, 'ca');
我希望输出应该是这样的:
Nameid|name|product|place|amount|price|expence|price + expence|amount - (price +expence) |
2 |john| dhal | Ny | 3000 | 100 | 280 | 380| 2620 |
1 |chan|chenna | At | 2000 | 150 | 500 | 650| 1350 |
3 |james| ghee | ca | 2000 | 400 | 600 | 1000| 1000 |
Total|------|-----|-----| 7000 | 650 | 1380 | 2030 | 4970