All pastes #474310 Raw Edit

Miscellany

public sql v1 · immutable
·published 2007-05-06 19:16 UTC
rendered paste body
SELECTcase when (final_hand like 'high card%') then 'High card' ELSEcase when (final_hand like 'a pair%') then 'A pair' ELSECASE WHEN (final_hand like 'two pair%') THEN 'Two pair' ELSECASE WHEN (final_hand like 'three of a kind%') THEN 'Three of a kind' ELSECASE WHEN (final_hand like 'a straight%') then 'a straight' elsecase when (final_hand like 'a flush%') then 'a flush' elsecase when (final_hand like 'a full house%') then 'a full house' elsecase when (final_hand like 'four of a kind%') then 'four of a kind' elsecase when (final_hand like 'a straight flush%') then 'a straight flush' end end end end end end end end end as final_hand_ab,/*not sure how to sum final_hands without using a redundant subquery so i was running the query once, totaling the raw count by hand, and then using that as TOTALNUMBER. ghetto, i know...*/--round(count(final_hand)::numeric/TOTALNUMBER*100,2) AS final_hand_countcount(final_hand) AS final_hand_countFROM(SELECT*,substring(hh.hand_history, 'FLOP.*?bets \\$([\\d.]*).*?TURN')::numeric as the_flop_bet,substring(hh.hand_history, 'FLOP.*?raises to \\$([\\d.]*).*?TURN')::numeric as the_flop_raiseFROM game gJOIN hand_histories hh ON g.game_number = hh.game_numberJOIN game_players gp ON g.game_id = gp.game_idJOIN players pl ON pl.player_id = gp.player_idAND hh.hand_history ~ ('FLOP.*?' || pl.screen_name || '[\\w\\s\\(\\)]*? raises.*?TURN')AND gp.went_to_showdown_n = 1)AS flop_raisesWHERE the_flop_raise < the_flop_bet * 2.1GROUP BY final_hand_ab ORDER BY final_hand_count DESC;