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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:59:41+00:00 2026-06-07T01:59:41+00:00

I’m writing up a reporting system for a recruitment website I made. So far

  • 0

I’m writing up a reporting system for a recruitment website I made. So far I’ve managed to get the function below to pull through total jobs over a given time period grouped in days, weeks months or years

What I’d like to do is pull through the total job applications for that same period. The job applications are stored in another table called job_application, and contain job_application_id, job_id and date_added fields

Is there a way I can pull that data through in the same query? The SQL is beginning to fry my brain so any help would be much appreciated!

public function getJobReport($data = array()) {
    $sql = "SELECT MIN(tmp.date_added) AS date_start, MAX(tmp.date_added) AS date_end, COUNT(tmp.job_id) AS `jobs` FROM (SELECT j.job_id, j.date_added FROM `" . DB_PREFIX . "job` j WHERE 1"; 

    if (isset($data['date_start']) && $data['date_start']) {
        $sql .= " AND DATE(j.date_added) >= '" . $this->db->escape($data['date_start']) . "'";
    }

    if (isset($data['date_end']) && $data['date_end']) {
        $sql .= " AND DATE(j.date_added) <= '" . $this->db->escape($data['date_end']) . "'";
    }

    $sql .= " GROUP BY j.job_id) tmp";

    if (isset($data['group'])) {
        $group = $data['group'];
    } else {
        $group = 'week';
    }

    switch($group) {
        case 'day';
            $sql .= " GROUP BY DAY(tmp.date_added)";
            break;
        default:
        case 'week':
            $sql .= " GROUP BY WEEK(tmp.date_added)";
            break;  
        case 'month':
            $sql .= " GROUP BY MONTH(tmp.date_added)";
            break;
        case 'year':
            $sql .= " GROUP BY YEAR(tmp.date_added)";
            break;                                  
    }

    if (isset($data['start']) || isset($data['limit'])) {
        if ($data['start'] < 0) {
            $data['start'] = 0;
        }           

        if ($data['limit'] < 1) {
            $data['limit'] = 20;
        }   

        $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
    }   

    $query = $this->db->query($sql);

    return $query->rows;        
}
  • 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-07T01:59:43+00:00Added an answer on June 7, 2026 at 1:59 am

    I don’t readily see why a subquery is necessary here…
    This Query uses a left join and selects as columns your input start and end dates, then GROUP’s by that (so there will be exactly one result row). I have skimped a little on the specifics of your identifiers to make this more readable.

    ...
    $date_resolution_function = "DAY"; // set via a switch similar to yours
    ...
    SELECT 
      $date_resolution_function(apps.date_added), 
      count(jobs.id) as numb_jobs, 
      count(apps.id) as num_apps
    FROM 
      jobs JOIN job_application as apps ON jobs.id = apps.job_id
    WHERE apps.date_added BETWEEN $start_date AND $end_date
    GROUP BY $date_resolution_function(apps.date_added)
    

    EDIT: Note that this technique requires your start and end dates to be set… but I highly suggest you define reasonable defaults anyway. If you want the defaults to be wide, use epoch and +100 years from now, or something… but perhaps something like “this quarter” is more appropriate for your client.

    EDIT 2 (adding date resolution): It is important to realize that with this kind of query, you can only get accurate date selection on EITHER jobs or applications, and the other will be “all”. I chose what I think is more sensible, to select on application date and include all jobs no matter when they were posted (IF they have applications submitted during the specified period). If you want the other way (only show jobs posted during the period), you can change the column passed to the date function, and make the JOIN a LEFT join… but keep in mind that the data for number of applications to that job will be for the ENTIRE period, not just the DAY/WEEK the job was posted.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I am writing an app with both english and french support. The app requests
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put

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.