mysql - Count all items on which a user is the high bidder -
i working on auction system, , functionality complete. need add count user's profile shows how many items user bidding on.
the system comprises of 2 key tables (extra tables feature in system of course, these tables related issue):
item_sales
:
+-----+------------------+------------+-------------+---------+ | id | selling_format | duration | list_date | buyer | +-----+------------------+------------+-------------+---------+
item_sales_bids
:
+-----+-------------+-----------+---------------+-----------+--------+ | id | sale_item | user_id | current_bid | max_bid | date | +-----+-------------+-----------+---------------+-----------+--------+
item_sales_bids
.date
unix timestamp of bid time.
i can count of bids given user has made following query:
select count(distinct(`item_sales_bids`.`user_id`)) `total`, sum((`sale`.`list_date` + (`sale`.`duration` * 86400)) - unix_timestamp()) `endtime` `item_sales_bids` inner join `item_sales` `sale` on `item_sales_bids`.`sale_item` = `sale`.`id` `user_id` = 1 group `sale_item` having `endtime` > 0
what do, run query similar above, include records specified user current highest bidder (i.e. max id entry given item's bid set has user_id
value = our user).
unfortunately, i'm @ loss on how might achieve this.
i have set sqlfiddle assist > http://sqlfiddle.com/#!2/b98e4/3
do subs query latest bid items , join item_sales_bids process latest items.
something this:-
select count(distinct(item_sales_bids.user_id)) total, sum((sale.list_date + (sale.duration * 86400)) - unix_timestamp()) endtime item_sales_bids inner join item_sales sale on item_sales_bids.sale_item = sale.id inner join ( select sale_item, max(id) latestbid item_sales_bids group sale_item ) sub1 on item_sales_bids.sale_item = sub1.sale_item , item_sales_bids.id = sub1.latestbid user_id = 1 group item_sales_bids.sale_item having endtime > 0
Comments
Post a Comment