question

sksql avatar image
sksql asked

how do i generate count based on the number of occurence of a number in a table

I have table like patient id, pat name, date where patient id is unique.I need generate count(like 1,2,3) of the patient's frequency based on date.Like lets say on jan 3rd the count should show 3 if the patient has visited till Jan 3rd for 3 times. I am using ssis (sql 2008). not sure i articulated well enough..let me know if this isn't good enough
row-counts
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Could you expound a bit more? Sounds like you just want a SELECT patient_id, [date], count(*) FROM table group by patient_id, [date]?
0 Likes 0 ·

1 Answer

·
Tim avatar image
Tim answered
Since you are wanting to GROUP BY PatientID since that is unique per patient, then Grouping them together and getting the count should work for you. A sample query is below. If this isn't what you are looking for please let me know. SELECT PatientName, COUNT (PatientID) AS Visits FROM YourTable WHERE Date
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I think the OP was going for a running count: PatientId Date VisitCount 1 01-Jan 1 1 02-Jan 2 1 03-Jan 3
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.