• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 32
  • Last Modified:

mysql statement - getting sum of a column from a joined table

Dear Experts,
I use MySQL
I have below select statement which works perfectly fine.
However, I need to have another sql statment for the sum(Totalim)
All I want is to select the sum of the Totalim where unqid='ceb447bbebe756a77f3440a969be7294'
how can I do that?

SELECT t.*,p.adet,t.alis*p.adet as Totalim 
FROM table1 t
INNER JOIN
( SELECT * FROM test ) p
ON p.id = t.id
where unqid='ceb447bbebe756a77f3440a969be7294'

Open in new window

0
BR
Asked:
BR
  • 2
1 Solution
 
Ryan ChongCommented:
what if trying this:

SELECT sum(t.alis*p.adet) as Totalim 
FROM table1 t
INNER JOIN
( SELECT * FROM test ) p
ON p.id = t.id
where unqid='ceb447bbebe756a77f3440a969be7294'

Open in new window


?
0
 
Ryan ChongCommented:
you can also write it as:

SELECT sum(t.alis*p.adet) as Totalim 
FROM table1 t
INNER JOIN
test p
ON p.id = t.id
where unqid='ceb447bbebe756a77f3440a969be7294'

Open in new window

1
 
BRMarketingAuthor Commented:
that is better, faster
thank you Ryan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now