-1

I want to multiply 2 columns in a single table the thing is one column is in the table but the other one is calculated.

My table structure :

cart_id(pk)    pro_id(fk)    pro_name    pro_price 

My query is:

SELECT *, COUNT(pro_id) AS ID 
FROM cart  
WHERE session_id='" . $_SESSION['session'] . "'
GROUP BY pro_id;

Now I want to calculate product price (pro_price) multiply ID which does not exist but calculated by product counts (count(pro_id)AS ID ).

basiclearner
  • 49
  • 1
  • 8

1 Answers1

0

try

select pro_id, sum(pro_price)
from cart
where session_id='" . $_SESSION['session'] . "'
group by pro_id

if the price is equal for all carts with identical pro_id, then sum(pro_price) equals count(*) * pro_price.

Ronald
  • 2,842
  • 16
  • 16