postgresql - Joined SQL query MAX aggregate with condition -


I am having trouble with SQL queries here my schema is represented on SQL Bedle:

< P>

The problem is that I want to return the row of data from the invitation table and both of them were created as well as new events along with 'sent' event_type and 'seen' event_type date.

I can get all the data and work, but there is a problem with the previous session. Is there any way I can use a condition in a MAX total work? Like

  maximum (SELECT events.created_at WHERE event_type = 'sent')  

If not, how do I write the correct subhead?

I am currently using Postgresql.

Thank you.

You can use a case statement inside Max as you did with the amount given below For the maximum created_at , select event_type = 'sent'

  i.id, i.name, i.email, max. (The case when last known as e.event_type = 'sent' then e.created_at end) as the last_cent_on, sum (in case when e.event_type = 'sent' then 1 and 0 termination) as_count, sum (case when e.event_type = See '1 and 0 to the end) to see I / O.Eventable_id = i.id But e-inventible_id = i.id WHERE e.eventable_type = 'invitation' group i.id, i.name, i.email  


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -