Jump to content

Recommended Posts

Ok here's what's giving me a problem.

 

I have a table with call records, which looks something like so.

 

[CALLDATE]  [COUNT_PNUMS] [CALLTYPE]  [FILENUMBER]

12/04/2009            11                    I                  123456

12/04/2009              5                    O                123456

12/01/2009            7                      I                  987654

 

My issue is, im trying to select a range of dates let's say between 12/01/2009 and 12/04/2009

That's the easy part... but then i want to display these dates cingularly, and not the amount of times they were pulled.

 

EXAMPLE:

SELECT calldate, count_pnums, calltype, filenumber FROM tablename WHERE calldate BETWEEN '$sDate' AND '$eDate' AND filenumber = '$filenum'";

 

So if i run a while loop echoing all my results... in this case 12/04/2009 will be echoed twice.

But for my purposes i only need to show it once, so i thought i could use a DISTINCT/UNIQUE clause in the query but that does not work when selecting multiple fields. So how can i do this while still pulling more than 1 field?

 

The above result would be like

 

12/04/2009  -  11  -  I  -  123456

12/04/2009  -  5    -  O  -  123456

12/01/2009  -  7    -    I  -  987654

 

But i need it to display like ...

 

12/04/2009  -  x  -  x  -  123456

12/01-2009  -  x  -  x    - 987654

 

The reason i left those #'s as X's is because during the do while loop i'd compute the totals per day.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/183992-selecting-distinct-issues-help/
Share on other sites

Well the calltype is definitely causing the issue. Technically the query is distinct, since one call type is I the other is O. There is no way around this, as far as I know other than leaving that field off. You may be able to do some fancy sub-querying (such as displaying total 16 - 11 I - 5 O in one line but I do not think it would be worth it, in my opinion.)

 

 

In mysql you would do the following (unknown if there is equivalent in ORACLE) -

 

SELECT calldate, SUM(count_pnums) AS total, filenumber FROM tablename
WHERE calldate BETWEEN '$sDate' AND '$eDate' GROUP BY calldate, filenumber

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.