Jump to content

Canman2005

Members
  • Posts

    669
  • Joined

  • Last visited

    Never

Posts posted by Canman2005

  1. That doesn't make sense.

     

    You have uid 1, cost 1.99 twice in your table... but you want to get only one occurrence of the uid's cost value..  But what if you had uid 1 , cost 2.34, so that they were no longer matching..  How would you decide which uid 1 cost value gets selected?

     

    If they are exact duplicates, why not just remove the duplicates..

     

    Currently, with that data you provided, the only way I know how to get 11.2 as an answer is to

    SELECT SUM(DISTINCT cost) FROM `yourTable`

    But that is only because none of the other uids have a matching cost value; it will break as soon as two different uids have the same cost value

     

    I say you should just remove the dupes..

     

    Two rows with the same UID number will never have different `cost` value, therefore I need to just add up how I explained, I tried the

     

    SELECT SUM(cost) AS DISCINCT(uid) FROM table

     

    but that didnt work

     

    Any ideas?

  2. Hi all

     

    I have the following table

     

    UID    COST

    1      1.99

    2      3.99

    1      1.99

    3      5.22

     

    As you will notice, there are 2 rows which have the same UID number

     

    How can I add up all of the COSTS using a

     

    SELECT SUM(cost) FROM `log`

     

    But if any rows have the same UID number, then it would only count one instance of that, so with the above table it would add up all of

     

    UID    COST

    2      3.99

    3      5.22

     

    and also just one instance of

     

    UID    COST

    1      1.99

     

    Giving a total of

     

    11.2

     

    Any help would be great

     

    Thanks

  3. Hi all

     

    I have a simple database, looks like

     

    name    type

    David    123

    Richard  123

    Sarah   

    Harry    999

    Bob     

    Brian      999

     

    Is it possible to do a QUERY (LIMITING to 3) and get all rows returned, but do a GROUP BY if any of the rows returned have matching `type` values, so it would looks like

     

    name    type

    David    123

    Sarah   

    Harry    999

    Bob

     

    Can anyone help?

     

    Thanks

     

    Dave

  4. Hi all

     

    I have a query to grab all rows in my table but it has a LIMIT 20 on it, so it just grabs the first 20 rows.

     

    I want to do a

     

    SELECT COUNT(*) as Num FROM

     

    but only do a count within the LIMIT I have set for my query.

     

    Is this possible?

  5. Thanks

     

    I have had a look, I see you can get the last monday by using

     

    date("d/m/Y",strtotime("last Monday"));

     

    but how would you say

     

    monday before last

    and the monday before that

     

    etc, can you just do

     

    date("d/m/Y",strtotime("last Monday"));

     

    and then run a -7 days?

  6. Please clarify what you really want. In your example, the first week of October should begin with [Monday] 2008-10-06 shouldn't it? I assume you want Mondays to be the first day of the week, but confirm that, too.

    It would be helpful to also do this if you can help
  7. Hi all

     

    Is it easy to print a list of months starting from a date set by

     

    $start = 2008-09-01;

     

    so it displays

     

    September 2008

    October 2008

    November 2008

    December 2008

     

    then print the weeks under each month, so it would look like

     

    September 2008

    Week 1 - 2008-09-01

    Week 2 - 2008-09-08

    Week 3 - 2008-09-15

    Week 4 - 2008-09-22

    Week 5 - 2008-09-29

    October 2008

    Week 1 - 2008-10-01

    Week 2 - 2008-10-08

    Week 3 - 2008-10-15

    Week 4 - 2008-10-22

    Week 5 - 2008-10-29

     

    thanks

  8. Nope it still produces that error, it seems to be with

     

    ($row['net_retail_price_exc_vat'] / $row['vat_rate'])

     

    if you change that to

     

    ($row['net_retail_price_exc_vat'] / 2)

     

    for example, it works fine

     

    any other ideas?

  9. Hi all

     

    I have the following table

     

    ID  UID  COST  VAT

    1    11    2.99    17.5

    2    11    1.99    17.5

    3    11    0.50   

    4    32    9.99    17.5

    5    23    2.40

     

    ID = Unique ID

    UID = User ID

    COST = Price (excluding VAT)

    VAT = VAT Percentage %

     

    What I want to do is grab all UID's with number 11, so a simple QUERY for this  would return;

     

    ID  UID  COST  VAT

    1    11    2.99    17.5

    2    11    1.99    17.5

    3    11    0.50   

     

    But what I want to then do is add up all the costs, so that would equal

     

    2.99 + 1.99 + 0.50 = 5.48

     

    But I also want to include the VAT % if one exists, so with the above it would be

     

    2.99 + VAT% = 3.51

     

    1.99 + VAT% = 2.34

     

    0.50 + VAT% = 0.50 (your notice 0.50 doesnt have a VAT value)

     

    So it would take those values and add them together, giving

     

    3.51 + 2.34 + 0.50 = 6.35

     

    Can this be done or will it require tons of QUERIES and adding values?

  10. Hi all

     

    I have a simple table which looks like

     

    ID    USER      PRICE

    1    10          12.00

    2    21          5.00

    3    21          10.00

     

    What I want to do is run a query and return all results with the `USER` with the highest value at the top.

     

    So with my example above, `USER` ID 10 has a total of 12.00 (ROW 1) and `USER` has a total of 15.00 (5.00 + 10.00) (ROW 2 and 3)

     

    So it would therefore return

     

    USER  TOTAL

    21      15.00

    10      12.00

     

    Can anyone help?

     

    Much love

     

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