public inbox for [email protected]
help / color / mirror / Atom feedFrom: Andreas Kretschmer <[email protected]>
To: [email protected]
Subject: Re: select with max functions
Date: Sun, 1 Oct 2017 20:48:45 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+t6e1mVtJveyoRRW8fLzY0tJhXntLrYxpSrk0=dDH8q93VPEA@mail.gmail.com>
References: <CA+t6e1mVtJveyoRRW8fLzY0tJhXntLrYxpSrk0=dDH8q93VPEA@mail.gmail.com>
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgsql-performance>
Am 01.10.2017 um 14:41 schrieb Mariel Cherkassky:
> Hi,
> I need to use the max function in my query. I had very bad performance
> when I used the max :
>
> SELECT Ma.User_Id,
> COUNT(*) COUNT
> FROM Manuim Ma
> WHERE Ma.Bb_Open_Date =
> (SELECT max(Bb_Open_Date)
> FROM Manuim Man
> WHERE Man.User_Id = Ma.User_Id
> )
> GROUP BY Ma.User_Id
> HAVING COUNT(*) > 1;
>
>
> Any idea how can I continue from here ? Thanks , Mariel.
Maybe you can rewrite it, for instance to
select distinct on (user_id, bb_open_date) user_id, bb_open_date,
count(1) from Manuim group by 1,2 having count(1) > 1;
maybe much cheaper, but untested! If not, please share more details, at
least table-definition.
Regards, Andreas
--
2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com
--
Sent via pgsql-performance mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: select with max functions
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox