Re: [GENERAL] sub-select with multiple records, columns

2017-06-19 Thread Israel Brewster
On Jun 19, 2017, at 12:29 PM, Thomas Kellerer wrote: > > Israel Brewster schrieb am 19.06.2017 um 22:17: >> SELECT >> ... >> (SELECT >> array_agg(to_json(row(notedate,username,note))) >> FROM sabrenotes >> INNER JOIN users ON author=users.id >> WHERE ticket=sabretickets.id ) notes >> FROM tickets

Re: [GENERAL] sub-select with multiple records, columns

2017-06-19 Thread David G. Johnston
On Mon, Jun 19, 2017 at 1:32 PM, David G. Johnston wrote: > On Mon, Jun 19, 2017 at 1:29 PM, Thomas Kellerer wrote: >> >> Israel Brewster schrieb am 19.06.2017 um 22:17: >>> >>> SELECT >>> ... >>> (SELECT >>> array_agg(to_json(row(notedate,username,note))) >>> FROM sabrenotes >>> INNER JOIN users

Re: [GENERAL] sub-select with multiple records, columns

2017-06-19 Thread Thomas Kellerer
Israel Brewster schrieb am 19.06.2017 um 22:17: SELECT ... (SELECT array_agg(to_json(row(notedate,username,note))) FROM sabrenotes INNER JOIN users ON author=users.id WHERE ticket=sabretickets.id ) notes FROM tickets WHERE ... The only problem with this query is that the notes aren't sorted. Of

Re: [GENERAL] sub select as a data column

2005-11-28 Thread Jim Buttafuoco
you were close, try the following (untesting). You need the alias on the outer my_table for this to work select year report_year, sum(amount), sum(select amount from my_table where year <= a.year) from my_table a group by report_year; -- Original Message --

Re: [GENERAL] sub select as a data column

2005-11-28 Thread Phong & Ronni Bounmixay
You both are SO right!  I sent that off and tried a couple of things and realized I was close but not close enough.  I really appreciate the kind responses.  Sometimes it's so hard to ask a question without feeling so foolish and then feeling worse when the answers are sarcastic.  Thank you! Good

Re: [GENERAL] sub select as a data column

2005-11-28 Thread Tom Lane
Phong & Ronni Bounmixay <[EMAIL PROTECTED]> writes: > I want to do in postgresql what I do in oracle: > select year report_year, > sum(amount), > sum(select amount from my_table where year <= report_year) > from my_table > group by report_year; That doesn't really work in Oracle

Re: [GENERAL] sub select

2001-08-30 Thread Tod McQuillin
On Thu, 30 Aug 2001, Ben-Nes Michael wrote: > Can I: > > select *, sum_rows as ( select count(*) from table2; ) from table1; I think you need to say: select *, (select count(*) from table2) as sum_rows from table1; But this won't be a very interesting query because the sum_rows column will be