SELECT `treport_question`, `treport_tema`,
COUNT(`treport_question`) AS cnt
FROM `treport`
LEFT JOIN `ttema` ON (`ttema`.`ttema_id` = `treport`.`treport_tema`)
LEFT JOIN `tquestions` ON (`tquestions`.`tquestions_id` = `treport`.`treport_question`)
LEFT JOIN `adm_test` ON (
`adm_test`.`admtest_user` = '2' AND
(`adm_test`.`admtest_type` = 'g' AND `adm_test`.`admtest_val` = `ttema`.`ttema_group`) OR
(`adm_test`.`admtest_type` = 't' AND `adm_test`.`admtest_val` = `ttema`.`ttema_id`) OR
(`adm_test`.`admtest_type` = 's' AND `adm_test`.`admtest_val` = `ttema`.`ttema_subject`)
)
WHERE `adm_test`.`admtest_id` IS NOT NULL
GROUP BY `treport_question`
Что получилось - в картинке)
А здесь - вместо того,чтобы искать похожие записи, считает все)
SELECT DISTINCT `tquestions_id`, `tquestions_question`, `treport_question`,
(SELECT COUNT(*) FROM `treport` WHERE `treport_question` = `treport_question`) AS `cnt`
FROM `treport`
LEFT JOIN `ttema` ON (`ttema`.`ttema_id` = `treport`.`treport_tema`)
LEFT JOIN `tquestions` ON (`tquestions`.`tquestions_id` = `treport`.`treport_question`)
LEFT JOIN `adm_test` ON (
`adm_test`.`admtest_user` = '".$GLOBALuser['user_id']."' AND
(`adm_test`.`admtest_type` = 'g' AND `adm_test`.`admtest_val` = `ttema`.`ttema_group`) OR
(`adm_test`.`admtest_type` = 't' AND `adm_test`.`admtest_val` = `ttema`.`ttema_id`) OR
(`adm_test`.`admtest_type` = 's' AND `adm_test`.`admtest_val` = `ttema`.`ttema_subject`)
)
WHERE `adm_test`.`admtest_id` IS NOT NULL
посоветуйте....
_____________
Одесса - мой город!)))