473,396 Members | 2,076 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,396 software developers and data experts.

UPDATE and DELETE double entries

Hello at all,

I have a question related to the Delete and Update Query.

The folowing table is given:


Expand|Select|Wrap|Line Numbers
  1. ContractID CarID Count Weight Earnings 
Explanation: In this table neither ContractID nor the CarID is the primary key. One example:
1 2 0.5 10 100
1 2 0.5 12 120
1 5 0.33 14 150
1 5 0.67 24 250

As you see the point of the table is to see how each car of each contract is divided. My aim is to merge those data with the same ContractID and CarID. From the example above it should result:

1 2 1 22 220
1 5 1 38 400


I was thinking to solve the problem in two steps:
1. Update Query (Sum all Count, Weight and Earnings with the same ContractID and CarID together and enter them in those fields):
1 2 1 22 220
1 2 1 22 220
1 5 1 38 400
1 5 1 38 400


2. Delete double entries (not the problem here)

So how to do the first step? Or is there another way to solve this problem?

I would be deeply grateful for any help. Thanks in advance.

BR,

Dete Vi Jete
Mar 16 '10 #1
3 1836
NeoPa
32,556 Expert Mod 16PB
A simple GROUP BY query is needed here. The data can stay as it is.
Expand|Select|Wrap|Line Numbers
  1. SELECT   ContractID,
  2.          CarID,
  3.          Sum([Count]) AS TotCount,
  4.          Sum([Weight]) AS Totweight,
  5.          Sum([Earnings]) AS TotEarnings
  6.  
  7. FROM     [YourTable]
  8.  
  9. GROUP BY ContractID,
  10.          CarID
Mar 16 '10 #2
Wow, thank you very much for the fast reply. I think I was thinking too complicated :).


Cheers,

Dete Vi Jete
Mar 16 '10 #3
NeoPa
32,556 Expert Mod 16PB
Always a pleasure Dete.

Welcome to Bytes!
Mar 16 '10 #4

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

Similar topics

2
by: news.la.sbcglobal.net | last post by:
hi all i am trying to update or delete a row/record in table cptcodes the error i am getting is key column information is insufficient or incorrect to many rows were affected by update.... ...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
by: ebc | last post by:
Hi, I have written a function that removes double entries from a sorted array. See the structures typedef struct tagRECR { char name;
4
by: Daniel | last post by:
Hi All, I have question regarding to the read, and update the row in the table. for example: user A, read the row of data from the table. user B, read the row of data from the table as well....
9
by: DraguVaso | last post by:
Hi, I'm writing a VB.NET application who has to insert/update and delete a whole bunch of records from a File into a Sql Server Database. But I want to be able to knwo the 'result' of my ctions....
2
by: dhakate123 | last post by:
Hi Friends.. I want delete repeated entries which comes twice in a table. How to delete that extra entry and keep each single entry using T-SQL statement(SQL server 2000). Please give me the...
0
by: saidev | last post by:
Hi All, One of the table has few data until yesterday and today when i query that table there are no rows. Can please anyone explain how to identify which user has delete and when last...
1
by: windandwaves | last post by:
Hi Folk I have a databse with a bunch of double entries in some fields. For example: field A: "that is the way to go that is the way to go "
0
by: steve proctor | last post by:
run time 70 permissions denied trying to update( delete info) on a vista Pc, how do i get round this, some say MTS??? but can't find that anywhere on the vista Pc, (using VB6)created the program on...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.