English 中文(简体)
INNER 加入《不回返总结果》
原标题:INNER join Return Not Returning total Results
  • 时间:2015-01-03 06:46:32
  •  标签:
  • mysql

贸易——数据 表1


代表行动价格


1 P-4, 3 P-3, 4 FS


2 SELL, 325


3 出售45 75


3支


表1


姓名


1 RCC


2 REG



SELECT SUM( IF( trade_data.action =   BUY , price, 0 ) ) AS   BUYSUM ,
       SUM( IF( trade_data.action =   SELL , price, 0 ) ) AS   BUYSELL , 
       AVG( trade_data.percent ) AS peravg, symbol. * 
FROM  `trade_data` 
INNER JOIN  `symbol` ON trade_data.symbol = symbol.id

This Query Gives me One Row But there Are Two Row are available at this Condition. But When I change the query As

SELECT trade_data.* , symbol. * 
FROM  `trade_data` 
INNER JOIN  `symbol` ON trade_data.symbol = symbol.id

Then this Query Gives me Exact 2 Rows.

最佳回答

Use group by with aggregate function ex.

SELECT SUM( IF( trade_data.action =   BUY , price, 0 ) ) AS   BUYSUM , SUM( IF( trade_data.action =   SELL , price, 0 ) ) AS   BUYSELL , AVG( trade_data.percent ) AS peravg, symbol. * 

FROM trade_data INNER JOIN symbol ON trade_data.symbol = symbol.id group by symbol.id

问题回答

www.un.org/Depts/DGACM/index_french.htm 因此,在这里,SUM(价格)将给你价格总额,增加每行的价格价值。 而总价值总是单一数值,因此,你们只能获得单一增长产出。

这种希望有助于。

您正在使用<代码>AVG()和SUM(功能,这就是为什么你们正在获得单一重整。

The AVG() Function
The AVG() function returns the average value of a numeric column.


The SUM() Function
The SUM() function returns the total sum of a numeric column.

如果您有多个<条码>贸易_数据.symbol = 符号.id。 (超过1例) 按分类,以获得每份记录的总和和平均数,并注明出处,因为只有1份<代码>,>symbol.id和trade_data.symbol。 你们只有一份记录。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签