adding HAVING cases
Guillermo Roditi [Wed, 16 Jul 2008 16:35:53 +0000 (16:35 +0000)]
etc/having-cases.sql [new file with mode: 0644]
lib/SQL/Abstract2.pm

diff --git a/etc/having-cases.sql b/etc/having-cases.sql
new file mode 100644 (file)
index 0000000..f0a655f
--- /dev/null
@@ -0,0 +1,31 @@
+
+-- CASE 1
+SELECT users.name, SUM(commission) AS total 
+  FROM commissions
+    INNER JOIN users ON ( commissions.recipient_id = users.id )
+  WHERE commissions.entry_date > '2007-01-01'
+  GROUP BY commissions.recipient_id
+    HAVING total > 500
+  ORDER BY total DESC;
+
+-- CASE 2
+SELECT users.name, aggregates.total FROM (
+       SELECT recipient_id, SUM(commission) AS total
+       FROM commissions
+       WHERE commissions.entry_date > '2007-01-01'
+       GROUP BY commissions.recipient_id
+       HAVING total > 500
+   ) AS aggregates
+INNER JOIN users ON(aggregates.recipient_id = users.id)
+ORDER BY aggregates.total DESC;
+
+-- CASE 3
+SELECT users.name, aggregates.total FROM (
+       SELECT recipient_id, SUM(commission) AS total
+       FROM commissions
+       WHERE commissions.entry_date > '2007-01-01'
+       GROUP BY commissions.recipient_id
+   ) AS aggregates
+INNER JOIN users ON(aggregates.recipient_id = users.id)
+WHERE aggregates.total > 500
+ORDER BY aggregates.total DESC
index e343268..508fa8b 100644 (file)
@@ -105,7 +105,7 @@ sub _build_known_ops {
      'where' => {
                  args_min => 1,
                  args_max => 1,
-                 handler => 'handle_op_sql_word_and_args'
+                 handler => 'handle_op_sql_word_and_args',
                 },
     );