duanhan5230 2013-11-03 20:13
浏览 33

如何对动态舍入值进行分组?

I keep getting no results in php, but I can see my query is returning multiple rows in phpMyAdmin; the thing that looks strange to me is that phpMyAdmin says 'showing rows 0-0' in phpMyAdmin even when many rows are shown. My main need is to get the data of each row in php.

I'm working with poker data in tables 'metrics' and 'hands'.

metrics has one row per nickname with 3 relevant columns. Example... nickname, AggPct, numHands

john, 0.3276, 160
mike, 0.4752, 200
saul, 0.4781, 100

hands has one row per poker hand with 2 relevant columns. Example... opponentNickname, netSmallBets

john, 7
john, 4
john, 9
mike, 8
mike, 2
saul, 20

I want a new intermediate table made from hands and metrics to look like this: nickname, netSmallBets, AggPct, numHands

john, 20, 33, 160
mike, 10, 48, 200
saul, 20, 48, 100

Then I want a final table (the final results I need) to look like this:

ev, numHands, AggPct
0.125, 160, 33
0.1, 300, 48

...where 'ev' is the sum of netSmallBets for a group of same AggPct, divided by sum of numHands in that group. i.e. mike and saul (10+20)/(200+100) = 0.1, and john is in his own group 20/160 = 0.125

The query I have is this:

SELECT 
SUM(h.netSmallBets)/SUM(m.numHands) ev, 
SUM(m.numHands) numHands, 
m.AggPct 
FROM 
(SELECT nickname, ROUND(100*AggPct) AggPct, numHands FROM metrics) m 
LEFT OUTER JOIN 
(SELECT opponentNickname, SUM(netSmallBets) netSmallBets FROM hands GROUP BY opponentNickname) h 
ON m.nickname=h.opponentNickname 
GROUP BY m.AggPct
ORDER BY m.AggPct ASC

It seems to work, except that my php document isn't getting any rows returned (I put a counter in the while loop that gets rows, and it never gets hit). When I run the exact same query in phpMyAdmin SQL prompt, it says 'Showing rows 0 - 0 (1 total...', but then it shows results like this...

ev, numHands, AggPct
0.60810810810811, 74, 9
1.6666666666667, 9, 17
1.6666666666667, 6, 19
2.8333333333333, 6, 20
0.74213836477987, 159, 21
-0.37777777777778, 45, 22

I need to be able to do some post-processing on each row individually in my php. Thanks for any help to be able to do this, I greatly appreciate it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探