日期:2014-05-16 浏览次数:21047 次
select id, stock_code, real_time, sum(if(stock_code=991156, buycount, 0)) as buycount, sum(if(stock_code=991156, bigbuycount, 0)) as bigbuycount, sum(if(stock_code=991156, waitbuycount, 0)) as waitbuycount, sum(if(stock_code=881155, buycount, 0)) as buycount, sum(if(stock_code=881155, bigbuycount, 0)) as bigbuycount, sum(if(stock_code=881155, waitbuycount, 0)) as waitbuycount from stock_data group by real_time order by real_time desc
------解决方案--------------------
select real_time,
MAX(if(stock_code=991156, buycount, 0)) as buycount,
MAX(if(stock_code=991156, bigbuycount, 0)) as bigbuycount,
MAX(if(stock_code=991156, waitbuycount, 0)) as waitbuycount,
MAX(if(stock_code=881155, buycount, 0)) as buycount,
MAX(if(stock_code=881155, bigbuycount, 0)) as bigbuycount,
MAX(if(stock_code=881155, waitbuycount, 0)) as waitbuycount
from stock_data group by real_time order by stock_code desc