Tech issues about computer, networks and programming and answers during or after my work. 工作及业余时间遇到的各种电脑,网络以及编程等相关的技术问题及解答
Oct 18, 2012
Do group by after order by in SQL
SELECT * FROM (
SELECT * FROM (
SELECT `m`.`id` AS `m__id`, `m`.`appliedat` AS `m__appliedat`, `m`.`idstudent` AS `m__idstudent`, `m`.`idclass` AS `m__idclass`, `m`.`comment` AS `m__comment`, `m`.`score` AS `m__score`, `m`.`created_by` AS `m__created_by`, `m`.`updated_by` AS `m__updated_by`, `m`.`deleted_at` AS `m__deleted_at`, `m`.`created_at` AS `m__created_at`, `m`.`updated_at` AS `m__updated_at`, `m`.`schoolcode` AS `m__schoolcode`, `c`.`id` AS `c__id`, `c`.`name` AS `c__name`, `c`.`code` AS `c__code`, `c`.`description` AS `c__description`, `c`.`idtype` AS `c__idtype`, `c`.`value` AS `c__value`, `c`.`idroot` AS `c__idroot`, `c`.`lft` AS `c__lft`, `c`.`rgt` AS `c__rgt`, `c`.`level` AS `c__level`, `c2`.`id` AS `c2__id`, `c2`.`name` AS `c2__name`, `c2`.`code` AS `c2__code`, `c2`.`description` AS `c2__description`, `c2`.`idtype` AS `c2__idtype`, `c2`.`value` AS `c2__value`, `c2`.`idroot` AS `c2__idroot`, `c2`.`lft` AS `c2__lft`, `c2`.`rgt` AS `c2__rgt`, `c2`.`level` AS `c2__level`, `c3`.`id` AS `c3__id`, `c3`.`name` AS `c3__name`, `c3`.`code` AS `c3__code`, `c3`.`idroot` AS `c3__idroot`, `c3`.`lft` AS `c3__lft`, `c3`.`rgt` AS `c3__rgt`, `c3`.`level` AS `c3__level`, `c4`.`id` AS `c4__id`, `c4`.`name` AS `c4__name`, `c4`.`code` AS `c4__code`, `c4`.`idroot` AS `c4__idroot`, `c4`.`lft` AS `c4__lft`, `c4`.`rgt` AS `c4__rgt`, `c4`.`level` AS `c4__level` FROM `mark` `m`
INNER JOIN `mark_criteria` `m2` ON (`m`.`id` = `m2`.`idmark`)
INNER JOIN `criteria` `c` ON `c`.`id` = `m2`.`idcriteria`
INNER JOIN `mark_criteria` `m3` ON (`m`.`id` = `m3`.`idmark`)
INNER JOIN `criteria` `c2` ON `c2`.`id` = `m3`.`idcriteria` AND (`c2`.`idtype` = 9)
LEFT JOIN `criteria_type` `c3` ON `c`.`idtype` = `c3`.`id`
LEFT JOIN `criteria_type` `c4` ON `c2`.`idtype` = `c4`.`id`
WHERE (`c`.`id` IN (46, 50) AND `m`.`idstudent` = 50 AND `m`.`idclass` = 12 AND (`m`.`deleted_at` IS NULL) AND ((`m`.`schoolcode` = 12345 OR `m`.`schoolcode` IS NULL)))
ORDER BY `m`.`appliedat` DESC, `m`.`created_at` DESC
) AS T
GROUP BY `c__id`
) AS T
ORDER BY `m__appliedat` DESC, `m__created_at` DESC
http://topic.csdn.net/u/20111024/18/4423fd26-60b5-4ed6-b541-16ba38d7356c.html
Labels:
SQL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment