Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

HELP QUERY, Modify Please

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
NeoAshura
Asked:
NeoAshura
  • 2
1 Solution
 
Lukasz ChmielewskiCommented:
$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
 
NeoAshuraAuthor Commented:
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
 
Lukasz ChmielewskiCommented:
Thank you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now