DotDragnet
February 08, 2012, 09:48:52 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Complicated SQL...  (Read 479 times)
Charisma Bypass
Hero Member
*****
Posts: 512



View Profile Awards
« on: August 31, 2010, 01:33:41 PM »

opi, oi, pi, pm, pn, pp, fp, pt, pq,
48,   42,   19,   blah,   blah,   49.99,   99.98,   0.00,   2
47,   42,   28,   test,   test,   18.99,   18.99,   0.00,   1

What I need to do is this:

Add the total value of pq and assign it to $total_units
Add the total value of pt and assign it to $total_price
Get the values of pi and output it comma separated to $product_ids
Get the values of pq that correspond with pi and output comma separated to $product_units
All of that based on oi

So, in the example above,
$total_units = 3
$total_price = 117.97
$product_ids = 19,28
$product_units = 2,1

Thank you in advance, I'm fuddled.
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 529



View Profile Awards
« Reply #1 on: August 31, 2010, 03:51:27 PM »

SELECT SUM(pq) AS total_units,
SUM(pt) AS total_price,
GROUP_CONCAT(pi) AS product_ids,
GROUP_CONCAT(pq) AS product_units
FROM sometable
WHERE oi = 42

Or possibly GROUP BY oi instead of WHERE, depending if you want one or all.
Logged
Charisma Bypass
Hero Member
*****
Posts: 512



View Profile Awards
« Reply #2 on: September 01, 2010, 12:26:54 PM »

Thank you very much Jason.  Very much appreciated.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!