[Bast-commits] r4583 - SQL-Abstract/1.x/branches/cleanup/etc
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Wed Jul 16 18:13:35 BST 2008
Author: matthewt
Date: 2008-07-16 18:13:35 +0100 (Wed, 16 Jul 2008)
New Revision: 4583
Modified:
SQL-Abstract/1.x/branches/cleanup/etc/having-cases.sql
Log:
groditi is now going to shout at me for making syntax up in 3, 2, 1 ...
Modified: SQL-Abstract/1.x/branches/cleanup/etc/having-cases.sql
===================================================================
--- SQL-Abstract/1.x/branches/cleanup/etc/having-cases.sql 2008-07-16 16:46:52 UTC (rev 4582)
+++ SQL-Abstract/1.x/branches/cleanup/etc/having-cases.sql 2008-07-16 17:13:35 UTC (rev 4583)
@@ -8,6 +8,40 @@
HAVING total > 500
ORDER BY total DESC;
+order_by { $_->total }
+ select { $_->users->name, [ total => sum($_->aggregates->commission) ] }
+ where { sum($_->aggregates->commission) > 500 }
+group_by { $_->commissions->recipient_id }
+ join { $_->users->id == $_->commissions->recipient_id }
+ [ users => expr { $_->users } ],
+ [ commission => expr { $_->commissions } ];
+
+my $total = [ -sum => [ -name => 'commission' ] ];
+
+[
+ -select,
+ [
+ -list,
+ [ -name => qw(users name) ],
+ $total
+ [
+ -where,
+ [ '>', $total, [ -value, 500 ] ],
+ [
+ -group_by,
+ [ -name, qw(commissions recipient_id) ],
+ [
+ -where,
+ [ '>', [ -name, qw(commissions entry_date) ], [ -value, '2007-01-01' ] ],
+ [
+ -join,
+ ...
+ ],
+ ],
+ ],
+ ],
+]
+
-- CASE 2
SELECT users.name, aggregates.total FROM (
SELECT recipient_id, SUM(commission) AS total
@@ -19,6 +53,21 @@
INNER JOIN users ON(aggregates.recipient_id = users.id)
ORDER BY aggregates.total DESC;
+order_by { $_->aggregates->total }
+ select { $_->users->name, $_->aggregates->total }
+ join { $_->users->id == $_->aggregates->recipient_id }
+ [ users => expr { $_->users } ],
+ [ aggregates =>
+ expr {
+ select { $_->recipient_id, [ total => sum($_->commission) ] }
+ where { sum($_->commission) > 500 }
+ group_by { $_->recipient_id }
+ where { $_->entry_date > '2007-01-01' }
+ expr { $_->commissions }
+ }
+ ];
+
+
-- CASE 3
SELECT users.name, aggregates.total FROM (
SELECT recipient_id, SUM(commission) AS total
@@ -29,3 +78,18 @@
INNER JOIN users ON(aggregates.recipient_id = users.id)
WHERE aggregates.total > 500
ORDER BY aggregates.total DESC
+
+
+order_by { $_->aggregates->total }
+ select { $_->users->name, $_->aggregates->total }
+ where { $_->aggregates->total > 500 }
+ join { $_->users->id == $_->aggregates->recipient_id }
+ [ users => expr { $_->users } ],
+ [ aggregates =>
+ expr {
+ select { $_->recipient_id, [ total => sum($_->commission) ] }
+ group_by { $_->recipient_id }
+ where { $_->entry_date > '2007-01-01' }
+ expr { $_->commissions }
+ }
+ ];
More information about the Bast-commits
mailing list