|
-
Aug 25th, 2016, 07:32 PM
#1
[RESOLVED] help looping my select statment
hey all,
I have this...
Code:
select company,sum(minutes) from production_table as A
right join customers as C
on A.customerID=C.id
where C.id=1
That returns a single row where c.id=1. How do eliminate the c.id=1 and return a row for every customer?
I'm using mysql if it matters
thanks
kevin
Last edited by kebo; Aug 25th, 2016 at 07:39 PM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 25th, 2016, 09:04 PM
#2
Re: help looping my select statment
Am I missing something? Wouldn't you just remove the WHERE clause?
-
Aug 26th, 2016, 06:38 AM
#3
Re: help looping my select statment
Removing the where clause was one of the first things I tried. When I did I ended up with the value of company field from the first row of table C and the sum total of all rows in table A.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 26th, 2016, 07:00 AM
#4
Re: help looping my select statment
Here is the sql for the table creation if it helps...
Table A:
Code:
CREATE TABLE `production_table` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`customerID` INT(11) NOT NULL,
`minutes` FLOAT NOT NULL,
PRIMARY KEY (`id`),
INDEX `FK_production_table_customers` (`customerID`),
CONSTRAINT `FK_production_table_customers` FOREIGN KEY (`customerID`) REFERENCES `customers` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=92
;
Table B:
Code:
CREATE TABLE `customers` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`company` VARCHAR(255) NOT NULL COLLATE 'latin1_general_ci',
PRIMARY KEY (`id`)
)
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 26th, 2016, 07:01 AM
#5
Re: help looping my select statment
Add the Group By
Code:
select company,sum(minutes) from production_table as A
right join customers as C
on A.customerID=C.id
Group by company
-tg
-
Aug 26th, 2016, 07:04 AM
#6
Re: help looping my select statment
Marvelous.
Thanks tg
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|