Sql 无论如何,我会保持这个循环。谢谢!是的,我有时需要调整规则,所以在这种情况下可能需要循环。我在正文中显示的数字只是我数据中的实际表格和结果。我猜代码中的块(只包含if-else语句)很难进行太多调整。 {1. @temp.ItemID = SUPPLY.I
Sql 无论如何,我会保持这个循环。谢谢!是的,我有时需要调整规则,所以在这种情况下可能需要循环。我在正文中显示的数字只是我数据中的实际表格和结果。我猜代码中的块(只包含if-else语句)很难进行太多调整。 {1. @temp.ItemID = SUPPLY.I,sql,sql-server,for-loop,Sql,Sql Server,For Loop,无论如何,我会保持这个循环。谢谢!是的,我有时需要调整规则,所以在这种情况下可能需要循环。我在正文中显示的数字只是我数据中的实际表格和结果。我猜代码中的块(只包含if-else语句)很难进行太多调整。 {1. @temp.ItemID = SUPPLY.ItemID; 2. @temp.Bid > SUPPLY.Price; 3. @temp.LowestDegre > SUPPLY.DegreeN.} {1. For the 2 rows (in the two tables
无论如何,我会保持这个循环。谢谢!是的,我有时需要调整规则,所以在这种情况下可能需要循环。我在正文中显示的数字只是我数据中的实际表格和结果。我猜代码中的块(只包含if-else语句)很难进行太多调整。
{1. @temp.ItemID = SUPPLY.ItemID;
2. @temp.Bid > SUPPLY.Price;
3. @temp.LowestDegre > SUPPLY.DegreeN.}
{1. For the 2 rows (in the two tables), DELETE both rows and the 1 corresponding row in dbo.DEMAND if Quantities are equal, or,
DELETE the row with smaller Quantity, and SUBTRACT the Quantity in the row with larger Quantity with the smaller one;
2. Add a row in the DEAL table, containing BuyerID, SellerID, ItemID, BidPrice, etc;
3. Redo the MATCH procedure.}
DECLARE @temp TABLE
(
buyer char(20),
bid float,
quantity smallint,
item char(20),
lowestnew decimal(18,2),
lowestrep decimal(18,2),
pubtime date
);
INSERT INTO @temp(buyer,bid,quantity,item,lowestnew,lowestrep,pubtime)
SELECT BuyerID,Bid,Quantity,ItemID,LowestDegreeNew,LowestReputation,PublishTime FROM DEMAND
ORDER BY PublishTime;
DECLARE @flag int
SET @flag = 0
DECLARE @seller char(20), @buyer CHAR(20), @item char(20), @lowestdegree decimal(18,2), @lowestrep decimal(18,2)
WHILE EXISTS (SELECT buyer, item, lowestnew, lowestrep FROM @temp)
BEGIN
SET @flag = 1
SELECT @buyer = buyer, @item = item, @lowestdegree = lowestnew, @lowestrep = lowestrep FROM @temp
DECLARE @price FLOAT, @quantity SMALLINT
IF EXISTS (select Price, SellerID, Quantity from SUPPLY, SELLER where SellerID = ID and @lowestdegree >= DegreeNew and @lowestrep>=Reputation order by Price)
BEGIN
SELECT TOP 1 @price=Price, @seller = SellerID, @quantity = Quantity FROM SUPPLY, SELLER WHERE SellerID = ID AND @lowestdegree >= DegreeNew AND @lowestrep>=Reputation
IF ((SELECT Quantity FROM DEMAND WHERE SellerID = @seller AND ItemID = @item AND (DegreeNew >= @LowestDegreeNew) AND (Price <= @bid)) IS NOT NULL)
BEGIN /* TRANSFER INTO NEW TABLE */
Supply: Day 1
Supply: Day 2
Demand: Day 2
Supply: Day 1
Supply: Day 2
Demand: Day 2
Demand: Day 3