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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:37:06+00:00 2026-06-13T07:37:06+00:00

I have the following db table which shows missed homework. CREATE TABLE `missed_homework` (

  • 0

I have the following db table which shows missed homework.

CREATE TABLE `missed_homework` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `studentid` int(10) NOT NULL,
  `subjectid` int(10) NOT NULL,
  `assignment_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `teacherid` int(10) NOT NULL,
  `date` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ... ;


INSERT INTO `missed_homework` (`id`, `studentid`, `subjectid`, `assignment_name`, `teacherid`, `date`) VALUES
(1, 29, 5, '5E', 20, '2012-10-18 13:58:40'),
(2, 15, 5, '32B', 20, '2012-10-18 13:59:54'),
(3, 29, 4, 'Q2A', 20, '2012-10-18 17:53:46'),
(4, 29, 11, '6E', 20, '2012-10-02 20:06:39'),
(5, 29, 11, 'C15', 20, '2012-10-16 20:06:30'),
(6, 15, 11, '7A', 20, '2012-09-19 20:08:05'),
(7, 29, 5, '3B', 20, '2012-09-14 20:08:12'),
(8, 29, 13, '6E', 32, '2012-10-18 20:23:46'),
(9, 29, 11, '7E', 18, '2012-10-20 14:35:14')......

I am not sure how to do the followings.

  1. I want to find total number of missed homework by say, studentid=29 grouped by month.
  2. same as above except grouped by week.

I tried the followings but it does not output what I want.

 $this->db->where('studentid',$id);
    $this->db->from('missed_homework');
    $this->db->group_by('date');
    $query=$this->db->get();
  • 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-13T07:37:08+00:00Added an answer on June 13, 2026 at 7:37 am

    I have used DATE_FORMAT() to get the name of the month and the number of week for each date.

    The following is the answer to your Question #1

    SELECT  studentID, 
            DATE_FORMAT(`date`, '%M') `month`,
            COUNT(studentID) totalMissed
    FROM hw_homework
    -- WHERE studentID = ''
    GROUP BY studentID, DATE_FORMAT(`date`, '%M')
    

    SQLFiddle Demo

    for Question #2

    SELECT  studentID, 
            DATE_FORMAT(`date`, '%U') `WeekNo`,
            COUNT(studentID) totalMissed
    FROM hw_homework
    -- WHERE studentID = ''
    GROUP BY studentID, DATE_FORMAT(`date`, '%U')
    

    SQLFiddle Demo

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

Sidebar

Related Questions

I have the following markup which shows a list of categories and subcategories: <table
I have a html table cell with the following data: <td>0/12 0%</td> which shows
I have the following table structure inside a view which gets displayed in the
I have the following situation: An Conversations entity/table which has multiple Tags associated to
I have the following table structure, which is imported into an Entity Framework project:
I have the following statement that I need to run on a table which
I have the following hsqldb table, in which I map UUIDs to auto incremented
I have an sql table which has the following rows. (4081, 3, '', 'contrapreneurship.jpg',
i have a table Students which contains the following colums: Id,FirstName,LastName,Adress . The colum
I have the following code which creates a new table. var html = '<table>';

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.