+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    02-09-2010
    Location
    Saint Louis
    MS-Off Ver
    Excel 2003
    Posts
    3

    Count the number of times two items appear in a table

    I have a table in my brain tumor database (Access 2003) that records the various surgical technologies that are used in each surgical case (tblPituitarySurgTech in attached example). Some surgeries involve the use of a surgical microscope. Some use a endoscope. Some use a surgical navigation system called "Stealth". I can write a query that totals the use of each item (qryPituitarySurgTech in the attached example). That 's easy. What I can't figure out is how to count, for example, the number of cases in which both a microscope and an endscope are used. It seems like this should be a simple thing to do. I just can't figure it out.
    Attached Files Attached Files
    Last edited by ResearchRN; 02-11-2010 at 12:10 PM.

  2. #2
    Forum Moderator ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2003 & 2010
    Posts
    1,799

    Re: Need query to count the number of times two items appear in a table

    Hi ResearchRN,

    Welcome to the forum!

    The result is a single cell:

    Code:
    SELECT Count(tblPituitarySurgTech.surgTech) AS [Endoscope or Microscope]
    FROM tblPituitarySurgTech
    WHERE (((tblPituitarySurgTech.surgTech)="endoscope" Or (tblPituitarySurgTech.surgTech)="surgical microscope"));

    Cheers,
    Docendo discimus.

    Please consider:
    • Thanking those who helped you. Click the reputation icon in the contributor's post and add Reputation.
    • Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    02-09-2010
    Location
    Saint Louis
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Need query to count the number of times two items appear in a table

    Quote Originally Posted by ConneXionLost View Post
    Hi ResearchRN,

    Welcome to the forum!

    The result is a single cell:

    Code:
    SELECT Count(tblPituitarySurgTech.surgTech) AS [Endoscope or Microscope]
    FROM tblPituitarySurgTech
    WHERE (((tblPituitarySurgTech.surgTech)="endoscope" Or (tblPituitarySurgTech.surgTech)="surgical microscope"));

    Cheers,
    Thanks for the welcome and your reply. However it's not quite what I'm looking for. The query appears to sum the number of times "endoscope" or " surgical microscope" appears in the table. What I need to know is how to find the number of cases in which both an endoscope and a microscope were used in the same case. For example, case number 36 used only an endoscope. Case number 37 used only a microscope. However case numbers 7, 114, and 178 used both. Just scanning the rest of the table it would appear that the total number of cases that used both would be 19 or so.

    Just to give you some background, nowadays these cases are done using an endoscope to gain access to the tumor and the microscope to remove it. In the past, they were done mostly by "eyeball". Then the microscope was added, then the endoscope. Now a lot of these cases are done using intra-operative MRI scanning. Lately they've been looking at 3D endoscopes in high def! The question we're trying to answer, among other things, is whether all these technologies really help and if so in what combination. It's the combination part I'm having trouble with.

    Thanks very much for your help.

  4. #4
    Forum Moderator ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2003 & 2010
    Posts
    1,799

    Re: Count the number of times two items appear in a table

    Sorry, my fault for not reading carefully.

    Try this:

    Code:
    SELECT Count(tblPituitarySurgTech.surgTech) AS [Endoscope and Microscope]
    FROM tblPituitarySurgTech INNER JOIN tblPituitarySurgTech AS tblPituitarySurgTech_1 ON tblPituitarySurgTech.caseNumber = tblPituitarySurgTech_1.caseNumber
    WHERE (((tblPituitarySurgTech.surgTech)="endoscope") AND ((tblPituitarySurgTech_1.surgTech)="surgical microscope"));

    If you want to see the case numbers, then use:

    Code:
    SELECT tblPituitarySurgTech.caseNumber, Count(tblPituitarySurgTech.surgTech) AS [Endoscope and Microscope]
    FROM tblPituitarySurgTech INNER JOIN tblPituitarySurgTech AS tblPituitarySurgTech_1 ON tblPituitarySurgTech.caseNumber = tblPituitarySurgTech_1.caseNumber
    WHERE (((tblPituitarySurgTech.surgTech)="endoscope") AND ((tblPituitarySurgTech_1.surgTech)="surgical microscope"))
    GROUP BY tblPituitarySurgTech.caseNumber;

    Cheers
    Docendo discimus.

    Please consider:
    • Thanking those who helped you. Click the reputation icon in the contributor's post and add Reputation.
    • Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Registered User
    Join Date
    02-09-2010
    Location
    Saint Louis
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Count the number of times two items appear in a table

    That's perfect! Thanks so much for taking the time to do this. I would never have gotten it on my own.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0