Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > Database & Database Programming

Database & Database Programming MySQL, Oracle, SQL, PL/SQL, ABAP, Smart Forms, and other databases and languages. A database is an organized body of related information used in many websites (including CC).

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-2007, 08:13 AM
reachpradeep's Avatar   
reachpradeep reachpradeep is offline
Learning Programmer
 
Join Date: Mar 2007
Location: India
Posts: 41
Rep Power: 7
reachpradeep is on a distinguished road
Send a message via MSN to reachpradeep
Default Adding a calculated column to a table

Having a problem with adding data to a column based on a calculated result from a second table. I seem to get the same result for all rows. It needs to be either an update or insert statement. It works as a select but that is about it. Here is the code. I need is to add a column to customers which I call Sales that takes the result from Orders and OrderItems table.
-----------------------
SELECT C.CustomerID, SUM(OI.Qty * OI.Price) AS Sales
FROM OrderItems OI
INNER JOIN Orders O
ON OI.InvoiceID = O.InvoiceID
INNER JOIN Customers C
ON O.CustomerID = C.CustomerID
AND O.CustomerID = C.CustomerID
INNER JOIN Products P
ON OI.ProductID = P.ProductID
GROUP BY C.CustomerID, C.CustomerID

Select * from Customers
-------------------------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
List of Values in Column Chan PHP Forum 6 08-16-2007 07:37 AM
ODBC API - Special Table and Column Names Tronman Database & Database Programming 0 07-30-2007 01:52 PM
Create temporary table in VB6 lfc1211 Visual Basic Programming 3 05-11-2007 05:29 PM
Flex, bison multifunction calculator annatsos C and C++ 1 01-04-2007 07:00 AM
Working with TADO Table MrDiaz Pascal/Delphi 0 07-03-2006 07:28 PM


All times are GMT -5. The time now is 11:48 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads