» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2006, 07:54 AM
Ahmed Ahmed is offline
Junior Member
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Ahmed is on a distinguished road
Default settling the table issues!

Hi there,
i have a table like this:

name: name of a stock
operation: can be 'b' or 's' (buy or sell)
quant: nuber of stocks to negotiate
user: the user
date: date of proposal
price: price of the stock


I want the query to output this:

name
buy: max price of buyers
sell: min price of sellers
quantbuy: quantity of stocks to negotiate
quantsell: quantity of stocks to negotiate

I've been trying with this:

SELECT tsell.name AS 'name', MAX( tbuy.price ) AS 'buy',
MIN( tsell.price ) AS 'sell', tbuy.quant AS 'quantbuy',
tsell.quant AS 'quantsell'
FROM proposals AS tsell, proposals AS tbuy
WHERE tsell.operation = 's'
AND tbuy.operation = 'b'
AND tsell.name = tbuy.name
GROUP BY tsell.name

But the quantity is not the one with that price, instead it is the first -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-05-2006, 07:56 AM
Beau Beau is offline
Senior Member
 
Join Date: Jul 2006
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 18
Beau is on a distinguished road
Default

Try this:

SELECT name,
max(if(operation='b',price,null)) AS buy,
min(if(operation='s',price,null)) AS sell,
sum(if(operation='b',quant,0)) AS quantbuy,
sum(if(operation='s',quant,0)) AS quantsell
FROM yourtable
GROUP BY name; -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to add posts to a phpbb table after moving servers. tanny MySQL Forums 3 02-13-2007 03:44 PM
adding value to the table. Eshur MySQL Forums 1 11-29-2006 06:36 AM
table dumping issues! Kiesler MySQL Forums 1 10-13-2006 05:36 AM
Math Op Addition of Values in repeated table gower PHP Programming and Tips 1 08-22-2006 01:39 PM
error= #1036 - Table 'table' is read only futuristic PHP Programming and Tips 1 08-12-2006 10:21 AM


All times are GMT. The time now is 08:27 PM.