Script started on Mon 27 May 2013 07:32:16 PM CEST ]0;wytze@webdb: ~/arbwytze@webdb:~/arb$ mysql caeccert Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 248792 Server version: 5.1.66-0+squeeze1-log (Debian) Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT count(1), YEAR(`users`.`dob`) as year from `users` WHERE -> -> YEAR(`users`.`dob`)>=1995 Group by YEAR(`users`.`dob`); +----------+------+ | count(1) | year | +----------+------+ | 500 | 1995 | | 297 | 1996 | | 242 | 1997 | | 177 | 1998 | | 309 | 1999 | | 185 | 2000 | | 54 | 2001 | | 35 | 2002 | | 56 | 2003 | | 68 | 2004 | | 92 | 2005 | | 89 | 2006 | | 100 | 2007 | | 98 | 2008 | | 76 | 2009 | | 92 | 2010 | | 64 | 2011 | | 37 | 2012 | | 6 | 2013 | | 2 | 2050 | | 1 | 2090 | | 1 | 2099 | | 1 | 2972 | | 1 | 2987 | | 1 | 3112 | | 1 | 4007 | | 1 | 4345 | | 2 | 7119 | | 1 | 7619 | | 1 | 7993 | | 1 | 9999 | +----------+------+ 31 rows in set (0.00 sec) mysql> SELECT -> -> count( `temp`.`no` ) AS AffectedUsers, -> -> sum( `temp`.`assurances` ) AS AffectedAssurances, -> -> if(points = 0, "No points", if(points < 50, "1 < x < 50", if(points < 100, "50 <= x < 100", "100 <= x"))) AS ReceivedPoints -> -> FROM ( SELECT 1 AS no, count( 1 ) AS assurances, sum( `notary`.`poi nts` ) AS points -> -> FROM `users`, `notary` -> -> WHERE YEAR(`users`.`dob`)>=1995 and `users`.`id`=`notary`.`to` -> -> GROUP BY `users`.`id` -> -> ) AS `temp` -> -> GROUP BY ReceivedPoints; +---------------+--------------------+----------------+ | AffectedUsers | AffectedAssurances | ReceivedPoints | +---------------+--------------------+----------------+ | 38 | 44 | 1 < x < 50 | | 26 | 264 | 100 <= x | | 20 | 74 | 50 <= x < 100 | +---------------+--------------------+----------------+ 3 rows in set (1.00 sec) mysql> \q Bye ]0;wytze@webdb: ~/arbwytze@webdb:~/arb$ exit exit Script done on Mon 27 May 2013 07:33:13 PM CEST