Jump to content
php.lv forumi

SUM(row * -1) atgriež 'dīvainu' rezultātu


andrisp

Recommended Posts

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ā ?

Link to comment
Share on other sites

×
×
  • Create New...