[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Query PHP/MYSQL question

Posted on 2011-03-16
10
Medium Priority
?
283 Views
Last Modified: 2012-05-11
Hello Experts,

I was wondering if it was possible to "add" together all the numbers contained in a table based on the "company name" I ask this because the company have more than one phone per a business and need to be added up and sorted dynamicly. from highest to lowest.

An example of my table is attached

So what im trying to do is get the following

Company                TOTAL SPEND
ANNA Norris           £178
PETER jones            £100

As you can see it adds up all fields where Anna norris is the company name. as totals it.. so this would ADD both mobile number spends together. Because two people have phones in One company.

It then would need be orderd from highest to lowest?

Is This possible with a query??

if not is there any other ways you can think of??

All help is appricated.




Untitled.jpg
0
Comment
Question by:NeoAshura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 3

Expert Comment

by:fabzster187
ID: 35146767
ORDER BY DESC

Should give u this
0
 
LVL 3

Expert Comment

by:fabzster187
ID: 35146773
sorry ORDER BY TOTAL SPEND DESC
0
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 750 total points
ID: 35146827
select sum(jan) as total from company group by company
union
select sum(feb) as total from company group by company
union
select sum(mar) as total from company group by company order by total desc

Try with this query, see if its work then you can use the same for the rest of the months
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 4

Assisted Solution

by:qasim_md
qasim_md earned 750 total points
ID: 35146866
This will give you what you want::::

select sum(total_spend),company from your_table group by company order by 1 desc

did this help ???
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35147145
Ill try these when I get back to computer just in a meeting atm. Thanks will keep u updated
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35147162
Btw total spend is NOT a table it is the total needing to be displayed by PHP once the motnhly totals have been added
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35148154
ok guys im back at computer, i tried

select sum(total_spend),company from your_table group by company order by 1 desc

but get the following error:

Unknown column 'total_spend' in 'field list'

Thats because total spend needs to be the value which is added together from the months....



I Also tried:

"select sum(Jan09) as total from Bill2009 group by company
union
select sum(Feb09) as total from Bill2009 group by company
union
select sum(Mar09) as total from Bill2009 group by company order by total desc

This returned me with a table but with blank fields...

Anymore Ideas?????
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35148169
P.S what ive got is the table as shown attached in my first opening question.

What i need from that table is the output of

Company     TOTAL SPEND
Just LTD        £200
Deck LTD       £150

THERE IS NO TOTAL SPEND COLUMN IN MY TABLE THIS MUST BE CREATE VIA ADDING UP THE JAN FEB ETC.. AND THEN SHOWING TOTAL SPEND AS THE OUTPUT USING PHP.

Is this possible??
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35155069
I solved my own problem. However some experts helped me get that answer so points will be awarded accordingly.
0
 
LVL 6

Author Closing Comment

by:NeoAshura
ID: 35155076
was not full answer, created the answer myself.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question