Canman2005
-
Posts
669 -
Joined
-
Last visited
Never
Posts posted by Canman2005
-
-
I tried
SELECT DISTINCT `uid`, SUM(cost) FROM
but it didnt seem to work
any ideas?
-
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
-
You are a dimond
Thanks mate
-
can anyone help?
-
-
Is it possible to do something like
GROUP BY `type` IF `type` != ''
that way it would group anything which has the same `type` value
-
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
-
thanks guys, much help
-
figured it out, thanks anyway
-
Hi all
I have a query which returns a bunch of rows which have values assigned to them, the results could look like
23
456
812
2
56
and so on...
Can you in PHP count those values up of the returned rows and then just print the total at the bottom?
-
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?
-
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?
-
Okay, I shall read the date() info pn php.net
thanks
-
It would be helpful to also do this if you can helpPlease 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.
-
I just need to show each week in each month and then show the date next to it
-
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
-
It's just set to 'text' only because it was an old database with lots of data and I didnt want to alter any data by changing the data type
-
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?
-
Thanks MrAdam, but still getting
Warning: Division by zero
any ideas?
-
I seem to get a
Warning: Division by zero
error when doing that, any ideas?
-
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?
-
You legend, cheers
-
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
-
Thanks everyone
Because my QUERY is quite complex now, I have decided just to run it twice.
Doing a SUM
in MySQL Help
Posted
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?