小编Rav*_*avi的帖子

SQL INSERT但避免重复

我想做一些快速插入,但避免重复到表中.为了论证,我们称之为MarketPrices,我一直在尝试两种方法,但不确定如何更快地进行基准测试.

INSERT INTO MarketPrices (SecurityCode, BuyPrice, SellPrice, IsMarketOpen)
SELECT @SecurityCode, @BuyPrice,  @SellPrice, @IsMarketOpen
EXCEPT
SELECT SecurityCode, BuyPrice, SellPrice, j.bool as IsActive FROM MarketPrices
CROSS JOIN (SELECT 0 as bool UNION SELECT 1 as bool ) as j
Run Code Online (Sandbox Code Playgroud)

要么

DECLARE @MktId int
SET @MktId = (SELECT SecurityId FROM MarketPrices 
              where SecurityCode = @SecurityCode 
              and BuyPrice=@BuyPrice 
              and SellPrice = @SellPrice)

IF (@MktId is NULL)  
BEGIN
    INSERT INTO MarketPrices (SecurityCode, BuyPrice, SellPrice, IsMarketOpen)
    VALUES
    (@SecurityCode,@BuyPrice, @SellPrice, @IsMarketOpen)
END
Run Code Online (Sandbox Code Playgroud)

假设这@whatever是存储过程中的输入参数.

我希望能够在BuyPrice或SellPrice或两者与之前的其他所有事件不同时为每个SecurityCode插入新记录.我不关心IsMarketOpen.

关于上述任何一种方法,有什么明显的愚蠢之处吗?一个比另一个快吗?

sql sql-server sql-server-2005

11
推荐指数
2
解决办法
2万
查看次数

这个函数如何将交错过程反转为x个子序列

我前几天在4clojure 完成了练习43,并检查了其他一些解决方案.一个人特别困惑我.

挑战要求您编写一个满足所有这些要求的函数:

(= (__ [1 2 3 4 5 6] 2) '((1 3 5) (2 4 6)))
(= (__ (range 9) 3) '((0 3 6) (1 4 7) (2 5 8)))
(= (__ (range 10) 5) '((0 5) (1 6) (2 7) (3 8) (4 9)))
Run Code Online (Sandbox Code Playgroud)

我的解决方案是:

(fn [l n] 
    (map #(map second %) (vals (group-by #(mod (first %) n) 
    (map vector (iterate inc 0) l)))))
Run Code Online (Sandbox Code Playgroud)

用户自己有这个解决方案: #(apply map list (partition %2 %1)) 我无法弄清楚它是如何工作的.

让我们解决第一个问题: …

clojure

4
推荐指数
1
解决办法
719
查看次数

标签 统计

clojure ×1

sql ×1

sql-server ×1

sql-server-2005 ×1