Jump to content

Recommended Posts

I have three dbase tables:

Project: Building a set of tables to record customer information, record selected uses of transportation, record the points earned from using certain types of transportation, record the total points in a database table.

 

Currently, these are the tables:
Code:

TEAM
teamID
teamName

LIVE DATA:
Live Data:
TEAM
1       Buttmunch
____________________________
ACTIVITY
activityID
activityName
activityValue

LIVE DATA:
ACTIVITY
1       Walking    50
2       Biking      60
3       Trolley     10

____________________________
ENTRY (this records when the team applied, there TEAM info, and the ACTIVITY they have chosen)
entryID
date
teamID
activityID

LIVE DATA:
ENTRY
1    2009-05-05    1     2
2    2009-05-05    1     3
3    2009-05-04    1     1

_______________________________
TEAM_TOTALS (this is where I get scatter brained)
tt_ID
teamID
activityID
entryID
totalPoints

LIVE DATA:
TOTAL POINTS
1    1    1    120

 

I need to know how I can calculate the total and record it in the TOTAL POINTS database table based on teamID.

 

Currently, with assistance from others, I have this:

Code:

 

SELECT teamName
     , date
     , activityName
     , activityValue
     , CASE WHEN activityName IS NULL
            THEN 'totals'
            ELSE 'details' 
        END AS sortkey
  FROM (
       SELECT team.teamName
            , entry.date
            , activity.activityName
            , activity.activityValue
         FROM team
       INNER
         JOIN entry
           ON entry.teamID = team.teamID
       INNER
         JOIN activity
           ON activity.ID = entry.activityID
        WHERE team.teamID = 2
       UNION ALL
       SELECT NULL
            , NULL
            , NULL
            , SUM(activity.activityValue) 
         FROM entry
       INNER
         JOIN activity
           ON activity.ID = entry.activityID
        WHERE entry.teamID = 2
       ) AS u
ORDER
    BY sortkey
     , date

 

I would appreciate anyone helping this newb finish this one up.

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/157650-total-calculations-post-to-dbase-table/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.