sql server - What SQL queries will help analyse a membership base? -


In our sports center, I would like to analyze the number of numbers and types of our members, but I'm having trouble exact With SQL queries.

A "membership" is an entry pass that helps you in specific activities in our sports center. They have a start and end date, they represent a valid period. They have an affiliate activity (such as "gym", "swimming", "group fitness", "rock climbing", etc.)

A member may have more than one subscription. Generally, their expiration period will expire before one can buy them, but they may have two (or more) valid (or current) subscriptions.

A little bit simpler, we have the following two tables:

Members - Store a member's data, these are the column IDs - member name (varchar) Unique ID for - Member's Name Gender (Membership) - Member's Gender NumGym (int) - The number of valid Gym is a member (Derivative)

and

 Membership - Sold by us All membership has been subscribed, these columns have type id (varchar) - Unique ID for membership type (c) Specifies the amount) MemberID (Int) - This subscription start date (Datetime) is identified for the member purchased - when the membership is valid from the expiration date (date time) - when the membership is valid for 

I might be able to ask:

  1. How many members currently have a valid "gym" near?
  2. For how many active members I have been on a given day

(1), I have tried the following:

  Announcement @A Day DateTime Set @Eday = Convert (DateTime, '2009-12-08', 102) Update Member Mm Set NumGym = (Select Subscriber Count (Member) where S. Member ID = MIID and s.TypeID = "Jim" and @edi between s.StartDate and s (endued)  

Although this does not produce the right result (ours about our membership And based on some manual calculations).

Able to get (1) to work, I have not tried (2) so far.

Any suggestions on questions for the production of?

How many members currently have a valid " Jim "is nearby

  SELECT COUNT (*) initial date and end date and type ID = 'gym'  

GETDATE () should be reduced here you understand bec That you want to understand the end date .

"How many members?" "How many members are there?" As it is not so.

So, how many members are there?:

  from SELECT COUNT (DISTINCT MemberID) subscription, where the start date and end date are @ Date:  

and "How many are nearby?":

  SELECT COUNT (*) subscriptions to start date and end date During @  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -