Results 1 to 2 of 2
  1. #1
    megabrown is offline Novice
    Windows XP Access 2003
    Join Date
    Nov 2010
    Posts
    18

    Basic query design question

    I'm fairly new to access and I'm creating a database to assess and analyze invertebrate (bug) biodiversity in freshwater lakes located within a particular region.

    To get representative individual bug counts for each lake, we sampled the two substrata (ie. Habitats) in which most freshwater bugs reside in. In other words we took at least one sample from the mud and at least one sample from cobble for each lake. In some cases samples were taken at multiple locations on each lake. Each sample was then processed in one of two ways and counts of the 115 species we are interested in were taken.

    I currently have tables setup as follows:

    tblSpecies
    -pkSpecies_ID
    -txtSpecies



    tblLakeSamples
    -pkLake_Sample_ID (autonumber, primary)
    -fkLake_ID (foreign key to tblLake)
    -fkProcessing_ID (foreign key to tblProcessing)
    -fkHabitat_ID (foreign key to tblHabitat)
    -dteSample (date field)

    tblLakeSampleDetail
    -pkLake_Sample_Detail_ID (autonumber, primary)
    -fkLake_Sample_ID (foreign key to tblLakeSamples)
    -fkSpecies_ID (foreign key to tblSpecies)
    -Species_Count (number field, double data type)

    I am currently trying to design a query to calculate the percentage of each inverterbrate species (eg. [# of spiders]/[total # invertebrates]) per sample (each sample is distinguished by a unique pkLake_Sample_ID value). My biggest challenge is designing the query on a 'per sample basis'.

    How should I approach this?

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you may use Dsum() to get total of counts.

    SELECT tblLakeSampleDetail.fkLake_Sample_ID, tblLakeSampleDetail.fkSpecies_ID, tblLakeSampleDetail.Species_Count / dSum("species_count","tblLakeSampleDetail","fkLake _Sample_ID=" & tblLakeSampleDetail.fkLake_Sample_ID)
    FROM tblLakeSampleDetail;




    or, if you care about performance, use join subquery:


    SELECT a.fkLake_Sample_ID, a.fkSpecies_ID, a.Species_Count, a.Species_Count/b.ttotal
    FROM tblLakeSampleDetail AS a INNER JOIN (select tblLakeSampleDetail.fkLake_Sample_ID, sum(tblLakeSampleDetail.Species_Count) as tTotal from tblLakeSampleDetail group by tblLakeSampleDetail.fkLake_Sample_ID) AS b ON a.fkLake_Sample_ID = b.fkLake_Sample_ID;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query Design Question
    By copegjc15 in forum Queries
    Replies: 7
    Last Post: 11-13-2010, 10:28 PM
  2. Basic design question
    By Brant in forum Access
    Replies: 2
    Last Post: 11-10-2010, 12:37 PM
  3. A basic question about database design
    By guitarbinge in forum Access
    Replies: 2
    Last Post: 11-05-2010, 03:29 PM
  4. Really basic question
    By jimlaw in forum Forms
    Replies: 1
    Last Post: 07-27-2009, 07:20 AM
  5. Basic Question
    By chris11590 in forum Forms
    Replies: 0
    Last Post: 08-04-2008, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums