andrisp Posted June 9, 2006 Report Posted June 9, 2006 Tabulas struktūra: CREATE TABLE `test` ( `id` int(10) unsigned NOT NULL auto_increment, `amount` int(10) unsigned NOT NULL default '0', `mat_id` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB; Ieliek pārīti rindiņas: INSERT INTO `test` VALUES (1, 200, 1); INSERT INTO `test` VALUES (2, 300, 1); Ja mēģinam: SELECT SUM(amount * 1) FROM test GROUP BY mat_id; Atgriež: 500 Ja mēģinām: SELECT SUM(amount * -1) FROM test GROUP BY mat_id; Agriež: 36893488147419102732 Kāpēc tā ?
v3rb0 Posted June 9, 2006 Report Posted June 9, 2006 mysql versija kāda? man -500 no otrā selecta sanāca un mysql 4.1.9-max
andrisp Posted June 9, 2006 Author Report Posted June 9, 2006 mysql 5. Bet vispār ja reizināšanu veic ārpus - SUM(amount) * -1, tad strādā
GedroX Posted June 9, 2006 Report Posted June 9, 2006 Nu tieši tādēļ, ka tips ir unsigned. Un 36893488147419102732 + 500 = 2^65.
Recommended Posts