Answer the question
In order to leave comments, you need to log in
How to correctly group rows into one by condition in Mysql?
Good day everyone!
There is a product table in "prod", a test one for an example
CREATE TABLE `prod` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`residue` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`reserve` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`code` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=MyISAM
AUTO_INCREMENT=7;
Answer the question
In order to leave comments, you need to log in
group by case when residue = 0 AND reserve = 0 then -1 else id end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question