Mysql группа по счетчику (сколько условий)
Привет, каждый
Я хочу;
- question_id 1 и ответ 2
- question_id 2 и ответ 2
- question_id 3 и ответ ve 2
- question_id 4 и ответ ve 2
- question_id 5 и ve ответ 2
Я бы хотел сгруппировать по группам по object_id и посмотреть, как для object_id соответствует количество условий в поле с именем match_ number.
Как результат;
Object_id Eşleşme_sayısı
1 3
2 5
Экран таблицы;
Таблица кодов sql;
CREATE TABLE `object_answers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`question_id` int(11) unsigned DEFAULT NULL,
`object_id` int(11) unsigned DEFAULT NULL,
`answer` int(2) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `object_answers_question_id_foreign` (`question_id`),
KEY `object_answers_object_id_foreign` (`object_id`),
CONSTRAINT `object_answers_object_id_foreign` FOREIGN KEY (`object_id`) REFERENCES `object` (`id`) ON DELETE CASCADE,
CONSTRAINT `object_answers_question_id_foreign` FOREIGN KEY (`question_id`) REFERENCES `question` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `object_answers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`question_id` int(11) unsigned DEFAULT NULL,
`object_id` int(11) unsigned DEFAULT NULL,
`answer` int(2) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `object_answers_question_id_foreign` (`question_id`),
KEY `object_answers_object_id_foreign` (`object_id`),
CONSTRAINT `object_answers_object_id_foreign` FOREIGN KEY (`object_id`) REFERENCES `object` (`id`) ON DELETE CASCADE,
CONSTRAINT `object_answers_question_id_foreign` FOREIGN KEY (`question_id`) REFERENCES `question` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;