OR
inner join ( select c1.ID, row_number() over ( partition by c1.accountid order by c1.CreatedDate desc ) as RowNum from Contact_Salesforce c1 ) b on c.ID = b.ID and b.RowNum = 1After "partition by" is the column (or columns) that will hold the unique criteria.
After "order by" are the columns to order your results by. Considering that if you want the first time someone opened an email then you will want to sort by EventDate in order or oldest date to newest (ASC - Ascending).
You can comma separate the partition by columns and order by columns if you need to have multiple criteria
Consider your primary key(s) in your Data Extension, For the above to work you would need PKs for SubscriberKey and EmailName
The actual columns you create in your sending data extension are debatable, but it is important when querying for a resend list of for Opened/Engaged that you exclude consideration of clicks to unsubscribe and view the privacy policy.
SELECT
c.id as contactid,
b.emailaddress,
'Held' AS status
FROM Contact_Salesforce c
INNER JOIN DATA_EXTENSION_BOUNCES b
ON c.email = b.emailaddress
WHERE b.emailaddress is not null
Copy the Data Extension and populate it with one value from the original DE. (ex. SELECT TOP 1 * FROM ORIGINAL_DE)
Export the single record and delete the new DE (you only needed it to get all the column names)
Open the downloaded file in excel, copy all of the column names and paste the transposed (so instead of across they are in rows).
Insert these 2 functions in the 2nd and 3rd columns:
Colmun B: =CONCATENATE(", pp.",A1)
Column C: =CONCATENATE(" , SUM(CASE WHEN p.",A1," IS NOT NULL THEN 1 ELSE 0 END) AS ",A1)
Build the below SQL query with the data you composed in Excel (line 3 comes from Column C, line 7 is column B):