Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:11:08+00:00 2026-06-02T10:11:08+00:00

I am new to SQL. I was given a coursework to report data of

  • 0

I am new to SQL. I was given a coursework to report data of usage over the last 2 month. Can someone help me with the SQL statement?

SELECT COUNT(Member_ID,Non_Member_Name) AS Pool_usage_last_2_months
FROM Use_of_pool
WHERE DATEDIFF(‘2012-04-21’,’2012-02-21’) 

What I meant to do is to count the total number of member usage(member_ID) and non member usage(no ID,name only) from the last two months and then output the name and date and time,etc. on the same report. Is there any SQL statement to output that kind of information? Correction/Suggestions are welcomed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:11:09+00:00Added an answer on June 2, 2026 at 10:11 am

    You need a different WHERE clause. Assuming your Use_of_pool table includes a Date/Time field, date_field:

    WHERE date_field >= #2012-02-21# AND date_field <= #2012-04-21#
    

    If date_field values can include a time component other than midnight, advance the end date range by one day to capture all the possible Date/Time values from Apr. 21:

    WHERE date_field >= #2012-02-21# AND date_field <= #2012-04-22#
    

    That should restrict the rows to match what I think you want. It should offer fast performance with an index on date_field.

    I’m unclear about the count(s) you want … whether it is to be one count for all visits (both member and non-member), or separate counts for members and non-members.

    Edit: If each row of the table represents a visit by one person, you can simply count the rows to determine the number of visits during your selected time frame.

    SELECT Count(*) AS CountOfVisits
    FROM Use_of_pool
    WHERE date_field >= #2012-02-21# AND date_field <= #2012-04-21#
    

    Notice each visit by the same person will contribute to CountOfVisits, which is what I think you want. If you wanted to know how many different people visited, we will need a different approach.

    Edit2:
    It sounds like you can use Member_ID and Non_Member_Name to distinguish between member and nonmember visits. Member_ID is Null for nonmembers and non-Null for members. And Non_Member_Name is Null for members and non-Null for nonmembers.

    If that is true, try this query to count member and nonmember visits separately.

    SELECT
        Sum(IIf(Member_ID Is Not Null, 1, 0)) AS member_visits,
        Sum(IIf(Non_Member_Name Is Not Null, 1, 0)) AS non_member_visits
    FROM Use_of_pool
    WHERE date_field >= #2012-02-21# AND date_field <= #2012-04-21#
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to C# and SQL. But over the last few years while
Please explain the SQL query given below. I m new with SQL and struggling
I'm new to SQL and could use some help in creating a database schema
I am new to SQL and been given a task. Following are the details:
I am new to SQL and given the following table Table , I would
Original Question: I am new to SQL server and can't quite find what I
Question: The new SQL Server 2008 database returns me values formatted English (date/float). Is
I am writing some new SQL queries and want to check the query plans
I'm relatively new SQL queries, and I'm trying to join two tables in order
I need to create an entirely new Sql Server 2008 database and want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.