473,387 Members | 3,821 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,387 software developers and data experts.

Problem Using Sum with Join

pls help me solve this problem

i have
Table StockTransaction
field:
Code |In |Out

Table StockMaster
field:
Code |Name

now i want to show Last Stock
i use this query

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. STOCKTRANSACTION.CODE,
  3. SUM(STOCKTRANSACTION.IN-STOCKTRANSACTION.OUT) AS TOTAL
  4. FROM STOCKTRANSACTION 
  5. GROUP BY STOCKTRANSACTION.CODE
it's work

but what i want is display the name with other field
i use this query but shows error

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. STOCKTRANSACTION.CODE,
  3. STOCKMASTER.NAME,
  4. SUM(STOCKTRANSACTION.IN-STOCKTRANSACTION.OUT) AS TOTAL
  5. FROM STOCKTRANSACTION 
  6. INNER JOIN STOCK MASTER
  7. ON STOCKTRANSACTION.CODE=MASTER.CODE
  8. GROUP BY STOCKTRANSACTION.CODE
if i add group by like

Expand|Select|Wrap|Line Numbers
  1. GROUP BY STOCKTRANSACTION.CODE,STOCKMASTER.NAME
It's work but the result is different ( some item shows double)


sory bad english
Mar 28 '08 #1
1 1150
amitpatel66
2,367 Expert 2GB
pls help me solve this problem

i have
Table StockTransaction
field:
Code |In |Out

Table StockMaster
field:
Code |Name

now i want to show Last Stock
i use this query

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. STOCKTRANSACTION.CODE,
  3. SUM(STOCKTRANSACTION.IN-STOCKTRANSACTION.OUT) AS TOTAL
  4. FROM STOCKTRANSACTION 
  5. GROUP BY STOCKTRANSACTION.CODE
it's work

but what i want is display the name with other field
i use this query but shows error

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. STOCKTRANSACTION.CODE,
  3. STOCKMASTER.NAME,
  4. SUM(STOCKTRANSACTION.IN-STOCKTRANSACTION.OUT) AS TOTAL
  5. FROM STOCKTRANSACTION 
  6. INNER JOIN STOCK MASTER
  7. ON STOCKTRANSACTION.CODE=MASTER.CODE
  8. GROUP BY STOCKTRANSACTION.CODE
if i add group by like

Expand|Select|Wrap|Line Numbers
  1. GROUP BY STOCKTRANSACTION.CODE,STOCKMASTER.NAME
It's work but the result is different ( some item shows double)


sory bad english
Try This:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT x.CODE, y.name, x.Total FROM
  3. (SELECT 
  4. STOCKTRANSACTION.CODE AS CODE,
  5. SUM(STOCKTRANSACTION.IN-STOCKTRANSACTION.OUT) AS TOTAL
  6. FROM STOCKTRANSACTION 
  7. GROUP BY STOCKTRANSACTION.CODE) x, STOCK MASTER y
  8. WHERE x.code = y.code
  9.  
  10.  
Mar 28 '08 #2

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

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
16
by: Ling Lee | last post by:
Hello. I'm trying to write a small program that lets you put in a number as an integer and then it tells you the textuel representation of the number. Like if your input is 42, it will say...
0
by: Mark | last post by:
I am having a problem getting my resultset to come out right. I am looking to join 3 tables getting a sum out of two and data out of the the third: Tables: users debits credits These...
2
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1...
2
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
1
by: lovkeshanand | last post by:
Dear All, I am using the oracle transparent gateway connectivity with sql server using tg4msql,as far as settings are concerned those were set and Connectivity is working Fine, and getting the...
27
by: John Salerno | last post by:
Ok, here's a problem I've sort of assigned to myself for fun, but it's turning out to be quite a pain to wrap my mind around. It's from a puzzle game. It will help if you look at this image: ...
1
by: imranpariyani | last post by:
Hi i have a severe performance problem with one of my views which has 6 to 8 joins .. any help will be appreciated.. the view is: CREATE OR REPLACE VIEW thsn.trade_view AS SELECT...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.