473,435 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,435 software developers and data experts.

How to SUM values in column where values in another column match.

I am trying to SUM values in a column where values in another column are the same.

Here is what I need, but I know the 5th line won't work:

Expand|Select|Wrap|Line Numbers
  1. UPDATE manufacturing_detail
  2. SET item_lead_time_1 = 
  3. (SELECT SUM(cycle_time)
  4. FROM routing_workcenter
  5. WHERE routing_workcenter.routing = routing_workcenter.routing)<---HELP!
  6. FROM manufacturing_detail, routing_workcenter
  7. WHERE manufacturing_detail.item = routing_workcenter.routing
Nov 1 '10 #1
7 4989
Try this

Expand|Select|Wrap|Line Numbers
  1. UPDATE manufacturing_detail 
  2. SET item_lead_time_1 =  
  3. (SELECT SUM(cycle_time) 
  4. FROM routing_workcenter 
  5. WHERE routing=manufacturing_detail.item)
Nov 2 '10 #2
The problem I am having is comparing the same column in a single table, just for different rows. Not a column in one table to a column in another table. There will be multiple records with the same value in the routing column, when this occurs, I want to sum the values in the cycle_time column for those matching records.
Nov 2 '10 #3
ck9663
2,878 Expert 2GB
Could you post some sample data and the result you want the query to return?


~~ CK
Nov 2 '10 #4
Here is a sample table:
routing_workcenter
routing_id routing status cycle_time
1 A A 10
2 A A 12
3 A A 15
4 B A 10
5 B A 10
6 B A 10
7 C A 15
8 C A 10
9 C A 25

What I want that 5th line of code to do is SUM based on the same value in the routing column. The results I am looking for would be:
A - 37
B - 35
C - 50

I then want to update item_lead_time_1 from table manufacturing_detail with these summed values.
Nov 3 '10 #5
ck9663
2,878 Expert 2GB
Where did you get the 35 for B? Or it should be 30 instead?

~~ CK
Nov 3 '10 #6
Yes, it should be 30. Sorry.
Nov 3 '10 #7
ck9663
2,878 Expert 2GB
Here, read this...

Happy Coding!!!

~~ CK
Nov 4 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Aaron C | last post by:
Hi, I'm trying to do an insert with the following statement: INSERT INTO user VALUES ( 'ag@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'',''); and I'm getting the error...
3
by: uw_badgers | last post by:
Is it possible to create a unique constraint to a column from another table? For example: tb_current: current_names -------------- aaa bbb tb_new:
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
1
by: Uli | last post by:
Hi, A collegue of mine has made an access entry field and keyed in all the data. Now I have to key in the same data in the same database. However, I first need to delete the values in several...
4
by: Ying Lu | last post by:
Hello, Under mysql, we have "desc tablename" to get the detail information about a table. My question is about to get column name, and column type for a specific table under PostgreSQL through...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
3
by: sql guy123 | last post by:
This is a real challenge. I hope someone is smart enough to know how to do this. I have a table TABLE1
4
by: drago | last post by:
Hi guys, I will be quick this time... Just want to know how we can calculate generic values in the same column. I am using invoice form with a services subform . I have a column of 'total' in subform...
0
VbaNewbee
by: VbaNewbee | last post by:
I have a form with a few filters. Once the user clicks "search button", the code first evaluates my filters, then shows the query results in a List Box" titled backschedule. I have a few text...
0
by: sk27ahmed | last post by:
Hi Any one can show me how to access datagridview column value on column checked unchecked. I create one column in datagridview of type checkbox,and on button click i write code to select all...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.