sql - count by on window function -


I created it that executes this query:

 select  " E-mail". * ("Sender_contact_id" command over "sender_contact_id" by "email" .id, sender_contact_id, sender_user_id, rank () by DESC "sent_at"), like "contact_rnk", more than rank (by "sender_user_id" order Partition "sent_at" by DESC) from "email" to "user_rnk" ("folder" = 'inbox')) "e" inner join "email" ("email". "Id" = "e". " Id ") Where (DESC sent by contact_rnk = 1 or user_rnk = 1 and folder = 'inbox') order;   

The point of the query is to return only 1 row for each contact or user, who has sent an email.

What's missing from the query that is the number of emails sent for each partition user or contact.

I can do it with many questions and can be involved in the end, eg. In the form of main (as select blbah, etc.)

 , as cnt_users (select counting (sender_user_id) joining the inner main etc.), (select count (sender_contact_id) ) Joining the inner main etc.) cnt_contacts selection main. *, Contents etc. Is it possible to include count in first query without using  group ?   

Rows can be counted without any GROUP BY each partition The trick is to use proper framing.

For example, the query can be modified as follows: ..

  Select "email" *, from e * (select "email" .id, sender_contact_id, sender_user_id, number ("w1") as "contact_rnk", count ( *) More than (the last and infinite w1 ROWS between the limitless ones) as CONTACT_COUNT, rank () OV ER (W2) like "user_rnk", count (*) "email" should be included internally at email_participants EP. id = ep.email_id Where (folder = 'inbox') is more than USER_COUNT (the last and the limitless of the limitless, between the following W2 ROWS) and user_id = 220 (sent_at DESC by sender_contact_id order PARTITION) In the form of email JOIN (emails.id = e.id) on e-interiors as window w1, w2 (by sender_user_id order, by PARTITION sent_at DESC) where ((contact_rnk = 1 or user_rnk = 1) and folder = ' Inbox ') should be sent_at by command DESC   

then e.contact_count and e.user_count each different sender_contact_id And sender_user_id . Message is calculated for

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -