Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

selecting both the price and sum(price ) with mysql statement

Dear Experts,

I have a very long sql statement. Below you may see the sort version of the sql. However I need more information like both the price and the SUM of the prices. How can I do that together? Can I use it like this?

I have a table that shows orders, I fetch the data and info from two tables, I show the prices but I want to show at the bottom of the table the total price too

is it possible to select data like below code? if I select the same column with SUM ( price ), and only price itself, how can I fetch the price and SUM (price) data?
$sql = "SELECT order._key, SUM (order.price), order.price, products.id, products.nkolayalis FROM order, products WHERE order.urunid = products.id";

$result = $conn->query($sql);

    // output data of each row
    while($row = $result->fetch_assoc()) {
        	
	$_key= $row["_key"];	
	$price= $row["price"];

Open in new window


    how about SUM of the prices?
    I need to both select the order.price and SUM(order.price)
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

Dear Vitor Montalvão,
So you suggest, I should use two Select sql sentence right?

That makes sense. Thank you
So you suggest, I should use two Select sql sentence right?
Exactly that.
Avatar of BR

ASKER

thank you
Avatar of BR

ASKER

Thank you Vitor Montalvao