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?

 

 

Link to comment
Share on other sites

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;

}

?>

Link to comment
Share on other sites

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.