我有一张桌子"提供"如下,
pid | sellerid | offer
1 | 1 | 30
1 | 2 | 32
1 | 3 | 31
2 | 2 | 60
3 | 3 | 45
我想要结果如下,
pid | seller1price | seller2price | seller3price
1 | 30 | 32 | 31
2 | -- | 60 | --
3 | -- | -- | 45
如果未找到记录,则可以将其替换为0或仅 - 。我尝试了跟随和许多其他方法,但没有得到空值
select a.pid as pid, a.offer as seller1price, b.offer as seller2price, c.offer as seller3price from offers as a, offers as b, offers as c where a.pid=b.pid and b.pid=c.pid group by a.pid;
但是这会跳过空记录而只获得第一条记录。我试过加入但也失败了。
任何帮助都可以被欣赏。