Skip to main content
added 27 characters in body
Source Link
blarg
  • 3.9k
  • 11
  • 47
  • 75

I have a table with two columns meetingID and caseID. The meetingIDs can be from one of three categories, so I use a subquery to select a particular one by returning only the meetingIDs from another table that match that category.

Once I have this list of meetingIDs I want to count how many of them have two caseIDs. I also need to exclude a few caseIDs from the count, but that's irrelevant for now.

Here's the code I have so far;

 select SELECT COUNT( meetingID from) case_meeting, wheremeetingID FROM case_meeting WHERE meetingID   IN (  SELECT DISTINCT a.meetingID FROM case_meeting a  INNER JOIN meeting b  ON a.meetingID = b.meetingID  WHERE  b.categoryID  = '1' and (case_meeting group'1' ) GROUP byBY meetingID having HAVING countCOUNT(caseID) =caseID 2); =2 

The main problem I have is actually writing code that will successfully count the number of meetingIDs that have two caseIDs instead of returning a list of them.

at the moment the code is returning a list where the number of rows matches the figure i want and in each row is a '2'

I have a table with two columns meetingID and caseID. The meetingIDs can be from one of three categories, so I use a subquery to select a particular one by returning only the meetingIDs from another table that match that category.

Once I have this list of meetingIDs I want to count how many of them have two caseIDs. I also need to exclude a few caseIDs from the count, but that's irrelevant for now.

Here's the code I have so far;

 select meetingID from case_meeting where meetingID IN(SELECT DISTINCT a.meetingID FROM case_meeting a  INNER JOIN meeting b  ON a.meetingID = b.meetingID  WHERE  b.categoryID  = '1' and (case_meeting group by meetingID having count(caseID) = 2); 

The main problem I have is actually writing code that will successfully count the number of meetingIDs that have two caseIDs instead of returning a list of them.

I have a table with two columns meetingID and caseID. The meetingIDs can be from one of three categories, so I use a subquery to select a particular one by returning only the meetingIDs from another table that match that category.

Once I have this list of meetingIDs I want to count how many of them have two caseIDs. I also need to exclude a few caseIDs from the count, but that's irrelevant for now.

Here's the code I have so far;

  SELECT COUNT( meetingID ) , meetingID FROM case_meeting WHERE meetingID   IN (  SELECT DISTINCT a.meetingID FROM case_meeting a INNER JOIN meeting b ON a.meetingID = b.meetingID WHERE b.categoryID = '1' ) GROUP BY meetingID HAVING COUNT( caseID ) =2 

The main problem I have is actually writing code that will successfully count the number of meetingIDs that have two caseIDs instead of returning a list of them.

at the moment the code is returning a list where the number of rows matches the figure i want and in each row is a '2'

Source Link
blarg
  • 3.9k
  • 11
  • 47
  • 75

Performing a count of column from another column in MYSQL

I have a table with two columns meetingID and caseID. The meetingIDs can be from one of three categories, so I use a subquery to select a particular one by returning only the meetingIDs from another table that match that category.

Once I have this list of meetingIDs I want to count how many of them have two caseIDs. I also need to exclude a few caseIDs from the count, but that's irrelevant for now.

Here's the code I have so far;

 select meetingID from case_meeting where meetingID IN(SELECT DISTINCT a.meetingID FROM case_meeting a INNER JOIN meeting b ON a.meetingID = b.meetingID WHERE b.categoryID = '1' and (case_meeting group by meetingID having count(caseID) = 2); 

The main problem I have is actually writing code that will successfully count the number of meetingIDs that have two caseIDs instead of returning a list of them.