【发布时间】:2014-02-04 10:48:41
【问题描述】:
好的开始 - 我搞砸了!
我有两个记录所有拍卖的表 - Bought & Sold - 每个 Sold 记录都有一个 bidID 值,将其连接到 Bought 记录。已购买的每件商品都有唯一的 itemID 值,但有时同一商品可能会被多次买卖。
以以下记录为例……
Sold Table:
listingID itemID bidID gamertag startPrice binPrice currentPrice listingEnds listingBought
----------- ---------------- --------- ------------------ ------------- ----------- --------------- ------------------------- -----------------------
18661 9011938655 4410 BoundenLeech84 3000 3100 3100 2014-01-31 18:59:20.000 2014-01-31 18:09:32.000
18825 9011938655 4410 BoundenLeech84 2800 2900 2900 2014-01-31 19:53:15.000 2014-01-31 18:54:48.000
Bought Table:
bidID itemID gamertag binPrice lowestBIN bidTime
----------- ---------------- ----------------- ---------- ----------- -----------------------
4410 9011938655 BoundenLeech84 2800 3300 2014-01-31 17:59:18
4454 9011938655 BoundenLeech84 2600 3100 2014-01-31 18:53:14
因此,listing ID 18661 的 bidID 为 4410,这是正确的,但 listingID 18825 的 bidID 也是 4410,这是不正确的,因为它应该是 4454(因为 bidID 4454 的 bidTime 是在 listingID 18661 的 listingBought 时间之后)。
像这样的记录有数百甚至数千条,所以我想知道是否有人知道是否有一种方法可以编写脚本来省去我手动执行的操作?
【问题讨论】:
-
还有其他方法可以识别哪一行是哪一行,因为 JOIN 列确实搞砸了。
-
并非如此 - 这是表中的所有字段。虽然我一次只会卖一次独特的物品(很明显),所以上面的例子我在 17.59 买了这个物品,然后在 18.09 卖了它,然后在 18.53 又买了 - 所以第二次购买的记录将永远是在 ListingBought 时间之后如果这有帮助,则保留 Sold 表中的第一条记录?
-
你用什么?Sql server,mysql?
-
@Mihai SQL Server 2008
标签: sql sql-server-2008 sql-update sql-scripts