MySql视图 - 显示同一表中另一列的数据

时间:2011-10-15 17:22:02

标签: mysql view

我有这个MySql View定义(使用Navicat完成):

SELECT DISTINCT
auctions.timelive AS timelive,
selections.id AS sel_id,
auctions.title AS `match`,
selections.title AS selection,
selections.odds AS odds,
auctions.bidprice AS bidprice,
(`auctions`.`bidprice` * (`selections`.`odds` - 1)) AS `next win rise`,
Sum((`auctions`.`bidprice` * (`selections`.`odds` - 1))) AS `pure winnings`,
selections.startamount AS startamount,
(sum((`auctions`.`bidprice` * (`bids`.`odds` - 1))) + `selections`.`startamount`) AS     `winnings with startamount`,
bids.`timestamp` AS `last bid on`,
Max(bids.id) AS `highest bid id`
from (((`bids` join `selections` on((`bids`.`selectionid` = `selections`.`id`))) join   `auctions` on((`bids`.`auctionid` = `auctions`.`id`))) join `users` on((`bids`.`userid` =  `users`.`id`)))
GROUP BY
selections.id,
bids.auctionid
ORDER BY
`last bid on` ASC

这项工作正常,但现在除了最后一个“出价最高出价ID”列之外,还希望在此视图中再添一列“bids.userid”,它基本上就是“最高出价ID”列的右侧。 怎么做? Canot找到解决方案!

1 个答案:

答案 0 :(得分:0)

...
Max(bids.id) AS `highest bid id`
,bids.`userid`
 ^^^^^^^^^^^^^ add this
from ...