Jump to content

[SOLVED] Question regarding couting results in a query?


Solarpitch

Recommended Posts

Hey,

 

I have a table that has a list of items that were sold on a POS system. Each item has an associated receipt number so the table would look like..

 

ID      PRODUCT      PRICE     RECEIPT NUMBER
---------------------------------------------
1       Budwiser       4.80       001
2       Carlsberg      4.80       001
3       Coke            2.20       001
4       Heineken       4.80       002
5       Coke            2.20       002

 

You can see that there are 3 items in the first sale (receipt 001) and two items in the second sale (receipt 002)

I'm basically looking to count the number sales in the table, not the rows.

 

There are 5 rows but only 2 sales. Wouls I use a group by clause to achieve this?

 

I think the query would need to group all the reciept numbers that are the same and count them as 1 sale?

 

 

This is the function here. (I'm using the Codeigniter Framework so the rest of the code just prints to screen)

 

It's like it doesnt even take the group by into consideration and just returns the total rows.

 

<?php

function total_sales($date)
{   

$query = $this->client->query('SELECT COUNT(ticketnumber) as total FROM sales WHERE date = '.$date.' GROUP BY "ticketnumber"');

$row = $query->row();
return $row->total;

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.