Jump to content

Recommended Posts

I'm done with this project, losing my mind and need help.

 

DB table has a column with phone numbers in it along with dates it was submitted.  Was asked to get a percentage of repeat incidents based on the phone numbers within 7 days of the first incident.

 

So i need to

[*]Get all phone numbers for the given month

[*]Check each phone number for repeat entries

[*]Get a tally of how many phone numbers have repeat entries

[*]Calculate a percentage for the month of phone numbers that have repeat entries compared to the total for the month.

 

Been working on this and have no code to show for it cause nothing I write can do this without killing the server or give me what I want.

 

Using codeigniter if that matters.

 

Can anyone get me started?!

Link to comment
https://forums.phpfreaks.com/topic/237694-need-help-with-crazy-query/
Share on other sites

Still working on this but i'm finding the way i'm querying is just not efficient.

 

Doing as follows.  Sorry for the codeigniter queries

 

//Get phone numbers for the entire month
$this->db->select('stn, submit_time');
$this->db->select('COUNT(stn) AS TOTAL');
$this->db->like('submit_date', YEAR_PREV_MONTH, 'after');
$this->db->not_like('level1', 'Abandon');
$this->db->not_like('stn', '9999999999');
$this->db->not_like('employee_id', '00000000');
$this->db->group_by("stn", "asc");
$data = $this->db->get('data');
$total_for_month = $data->num_rows();

$i = 0;

foreach ($data->result() as $row)
{	
    if($row->TOTAL > 1)
{
	$start = $row->submit_time - 604800;
	$end = $row->submit_time;
	$dateRange = "submit_time BETWEEN '$start' and '$end'";

	$this->db->select('data_id');
	$this->db->where($dateRange, NULL);
	$this->db->where('stn', $row->stn);
	$query = $this->db->get('data');
	$stn_data = $query->row();
	$i++;
}
}

echo "Total Individual STN's Found = ".$total_for_month;
echo "<br>";
echo "Incidents found with duplicate within 7 days = ".$i;
echo "<br>";

$total_distinct = $total_for_month - $i;
echo "Incidents with FCR = ".$total_distinct;
echo "<br>";

$a = $total_distinct * 100;
$b = $a / $total_for_month;

echo "<br><b>Group FCR for current Month = ".round($b, 2)."%</b>";
echo "<br><br>This shows the FCR for all calls for the current month for the entire group.";
echo "<hr />";

die();

 

I know this is the wrong way to do this, but for the life of me, can't figure out any other way.  With it like this, its running like 20,000 queries

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.