Solved

HELP QUERY, Modify Please

Posted on 2011-03-24
3
287 Views
Last Modified: 2012-08-14
Hi Experts, I have This query (code attached)

It works now but i need to add another column for the number of handsets a user owns. to do this i need to count the number of rows in the customer_details table where the customer_name is the name of the company to the left column. for example if Anna norris has 4 records in out customer_details table then she would have 4 handsets by counting the individual rows (indeitfied by the mobile_number) which is unique to one person obviously.

So this query needs changeing to include the customer_details table count every mobile number which = the company name and display the output in the column to the right of company in the  attached picture. see code and picture.

Many thanks for your time.
$query2 = "SELECT SUM(Jan09), SUM(Feb09),SUM(Mar09),SUM(Apr09),SUM(May09),SUM(Jun09),SUM(Jul09),SUM(Aug09),SUM(Sep09),SUM(Oct09),SUM(Nov09),SUM(Dec09) FROM bill_detail2009"; 

This is the query i know there is a join needing to be used somewhere just dont know where or how to get my desired output.

Open in new window

newpicture1.jpg
0
Comment
Question by:NeoAshura
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35206764
$query2 = "SELECT company_name, count(customer_name) as howmuch, SUM(Jan09), SUM(Feb09),SUM(Mar09),SUM(Apr09),SUM(May09),SUM(Jun09),SUM(Jul09),SUM(Aug09),SUM(Sep09),SUM(Oct09),SUM(Nov09),SUM(Dec09) FROM bill_detail2009 left join customer_details on customer_name = company_name";

try it or post some more - it would be nice to have a tables structure
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35206897
Ive sorted this now, What i did was insted of using the customer name, I added the unquie mobile numbers in the table of the customer based on the customer name so if 4 numbers had the same customer the count would be 4 and so on.. This is sorted but yours would work too so i will award points.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35206903
Thank you.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 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