Select sale.preselRef As ref,
sale.name,
sale.saledate,
sale.grandtotal,
sale.secid,
sale.invoicetype As typ,
Sum(sellnote.Paid) As cash,
Sum(sellnote.CreCard) As card,
Sum(sellnote.PCheck) As cheque,
Sum(sellnote.Compens) As compen,
sale.grandtotal - Sum(sellnote.Paid) - Sum(sellnote.CreCard) -
Sum(sellnote.PCheck) - Sum(sellnote.Compens) As balanc
From sale, sellnote
Where sale.preselRef = sellnote.Code
Group By sellnote.Code
Having sale.grandtotal - Sum(sellnote.Paid) - Sum(sellnote.CreCard) -
Sum(sellnote.PCheck) - Sum(sellnote.Compens) <> 0
CREATE TABLE IF NOT EXISTS `sale` (
`preselRef` int(12) NOT NULL,
`nameid` int(11) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`cusaddress` varchar(255) DEFAULT NULL,
`saledate` date DEFAULT NULL,
`datesent` date DEFAULT N开发者_开发百科ULL,
`vat` decimal(4,2) DEFAULT NULL,
`total` decimal(10,2) DEFAULT NULL,
`vatinbill` decimal(10,2) DEFAULT NULL,
`grandtotal` decimal(10,2) DEFAULT NULL,
`distcount` decimal(10,2) NOT NULL DEFAULT '0.00',
`secid` int(11) DEFAULT NULL,
`invoicetype` enum('d','r','u','i','z') NOT NULL DEFAULT 'u',
`remark` varchar(255) DEFAULT NULL,
`paid` decimal(10,2) DEFAULT NULL,
`cardno` varchar(200) DEFAULT NULL,
`creditcardamount` decimal(10,2) DEFAULT NULL,
`Bankcard` varchar(200) DEFAULT NULL,
`cheqno` varchar(200) DEFAULT NULL,
`chequeamount` decimal(11,2) DEFAULT NULL,
`bankcheque` varchar(200) DEFAULT NULL,
`asgreeno` varchar(200) DEFAULT NULL,
`checkcleardate` date DEFAULT NULL,
`Checktype` enum('r','s') NOT NULL,
`datetime` datetime DEFAULT NULL,
`timestamp` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`preselRef`),
UNIQUE KEY `salein` (`preselRef`),
UNIQUE KEY `saleid` (`secid`,`invoicetype`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `sellnote` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Code` varchar(11) NOT NULL DEFAULT '',
`Pdtail` varchar(200) DEFAULT NULL,
`Paid` decimal(12,2) NOT NULL DEFAULT '0.00',
`CreCard` decimal(12,2) NOT NULL DEFAULT '0.00',
`PCheck` decimal(12,2) NOT NULL DEFAULT '0.00',
`Compens` decimal(12,2) NOT NULL DEFAULT '0.00',
`DateDue` date DEFAULT NULL,
`BillCan` enum('Y','N') NOT NULL DEFAULT 'N',
`Remark` varchar(150) DEFAULT NULL,
`staff` varchar(50) DEFAULT NULL,
`Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `Code` (`Code`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Transaction Header' AUTO_INCREMENT=4943 ;
I have one row intable sale 4058 613 บริษัท เดอ ละไม จำกัด 171/4-9 หมู่4 ต.มะเร็ต อ.เกาะสมุย จ.สุราษฎร์ธานี 2011-08-01 NULL 7.00 3271.03 228.97 3500.00 0.00 10069 i NULL 0.00 0.00 0.00 NULL NULL NULL
and do not have sellnote.Code = 4058 but the row of the table sale that have sale.preselRef it should show but it do not show I have a bout 5000 record and only this row that i found the problem plese help
精彩评论