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 7693443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:05:23+00:00 2026-05-31T21:05:23+00:00

I working on a table that keeps record of student attending course. The data

  • 0

I working on a table that keeps record of student attending course. The data are keep using student identification number, course id, coursename, start date, end date. Student can take more than one course so there are repeating student identification number but with different course id, course name, start date and end date. What I’m trying to to here is to select students based on number of day using DATEDIFF.

Sorry for not explaining my problem properly. the structure of the table i’m talking about:

studcourse1(internalstudentid, staffnoic, courseid, coursenm, StDt, EndDt, location, organizer, generalcategorycd, generalsubcategorycd, eid)

staffnoic – staff identification number,
StDt – Start Date.
EndDt – End Date

I’ve checked, there’s no primary key or indexes on this table as it’s not a base but a view.

Sorry if the previous statement is too long. Let’s use this instead.

SELECT GradeGroupCd, StudCourse1.StaffNoIC, (DATEDIFF( EndDt, StDt ) +1) TotalDay, StDt, EndDt
          FROM StudCourse1, tblStaff, tblRefTitleGred
          WHERE tblStaff.TitleGredCd = tblRefTitleGred.TitleGredCd
          AND StudCourse1.StaffNoIC = tblStaff.StaffNoIC
          AND StDt >= '2009-1-1' AND YEAR(EndDt) <= YEAR(NOW())
          AND (DATEDIFF( EndDt, StDt ) +1) > 90
          AND (GeneralSubCategoryCd = 'S0012' OR GeneralSubCategoryCd = 'S0014')
          GROUP BY GradeGroupCd, StudCourse1.StaffNoIC

The statement above fetches results for student(using staffnoic from table tblStaff and table StudCourse1) having taking course for more than 90 days using (DATEDIFF(EndDt, StDt) + 1). What that really confuse me is that for example a record from studcourse1 with staffnoic of ‘111111111111’, sample data:

studcourse1(internalstudentid, staffnoic, courseid, coursenm, StDt, EndDt, location, organizer, generalcategorycd, generalsubcategorycd, eid)
studcourse1(10629,111111111111,AAA1811,Course1,2010-01-01 00:00:00, 2010-12-31 00:00:00, '', ABC Org, G003, S0012, E00001812)
       (30684,111111111111,AAA6968,Course2,2009-02-10 00:00:00, 2012-02-09 00:00:00, '', ABC Org, G003, S0012, E00006894)
       (30685,111111111111,AAA6970,Course3,2011-01-01 00:00:00, 2012-02-09 00:00:00, '', ABC Org, G003, S0014, E00006896)

Running the SQL statement will select the one with the StDt of 2010-01-01 00:00:00 and EndDt of 2010-12-31 00:00:00. Why is it singling out that record and not others as they all fall under AND StDt >= ‘2009-1-1’ AND YEAR(EndDt) <= YEAR(NOW())”. Year now referring to year 2012. How can I make it select the one with the StDt(2009-02-09) and EndDt(2012-02-09)?

And also “(DATEDIFF( EndDt, StDt ) +1) > 90”, why does it add 1 to it? Wouldn’t DATEDIFF( EndDt, StDt ) > 90 be the right one?

Sorry if that too many questions. Just learn MySQL recently. Thank you for your time.

  • 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-05-31T21:05:24+00:00Added an answer on May 31, 2026 at 9:05 pm

    Ok it is hard to understand what you have written. Please provide the tables you have used and the structure.

    Simplest method to get this done is having 3 tables,
    1) students with student id, name and so on
    2) Course – course id, course name and so on.
    3) Enrolment – enroll id, start date, end date and foreign keys(student id and course id).

    And I didnt get what you meant by (What I’m trying to to here is to select students based on number of day using DATEDIFF.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a website that has Employee and Branch entities, using a database table
I'm working on a legacy database table that has a phone no. field but
The database I'm working against has table names such as table_name. That's fine, but
I'm working on a project that will have a single table holding lots and
I am working on a form that adds employee information to a MySQL table
I'm working with a datagrid and adapter that correspond with an MSAccess table through
In a project that I'm working, there's a table with a on update trigger,
I'm working on creating a SQL query that will pull records from a table
I'm working on a sortable table, that is refreshed asynchronously when the column headers
I have a table that keeps track of the letters we send to our

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.