From: Guillermo Roditi <groditi@cpan.org>
Date: Wed, 16 Jul 2008 16:35:53 +0000 (+0000)
Subject: adding HAVING cases
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6eaca42329bbe870c7df60979777a814cfeffaa6;p=dbsrgits%2FSQL-Abstract.git

adding HAVING cases
---

diff --git a/etc/having-cases.sql b/etc/having-cases.sql
new file mode 100644
index 0000000..f0a655f
--- /dev/null
+++ b/etc/having-cases.sql
@@ -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
diff --git a/lib/SQL/Abstract2.pm b/lib/SQL/Abstract2.pm
index e343268..508fa8b 100644
--- a/lib/SQL/Abstract2.pm
+++ b/lib/SQL/Abstract2.pm
@@ -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',
                 },
     );