mysql - Count and group by in same query -


bid_count returning 1 ... how return correct bid count? know it's not returning right count because i'm grouping user_id. can alter query counts also.

"select id, bid, item_id, user_id, max(bid) max_bid, count(bid) bid_count, bid_date   bids   item_id = ?    group user_id order id desc" 

you shouldn't use unaggregated expressions in group unless same within group.

if want return record holding counts user_id, should use subquery counts join them result:

select id, bid, item_id, user_id, bid_date, max_bid, bid_count   bids left join   (select user_id,max(bid) max_bid, count(bid) bid_count      bids     item_id = ?      group user_id ) group_table on bids.user_id = group_table.user_id bids.item_id = ?  

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

How to connect android app to App engine -

hadoop - Running Map Reduce Job shows error - Mkdirs failed to create /var/folders/ -