我试图找到与此完全相反的查询:
#existing list
myList <- list(mean=c(1:10),
sd=c(11:15))
#new dataframe
df1 <- data.frame(x=1:10,
y=11:20)
#add dataframe
myList$df <- df1
#result
str(myList)
#output
# List of 3
# $ mean: int [1:10] 1 2 3 4 5 6 7 8 9 10
# $ sd : int [1:5] 11 12 13 14 15
# $ df :'data.frame': 10 obs. of 2 variables:
# ..$ x: int [1:10] 1 2 3 4 5 6 7 8 9 10
# ..$ y: int [1:10] 11 12 13 14 15 16 17 18 19 20
(这个SQL很好。&#34; word&#34;设置为唯一且一切)
所以,基本上,递减计数器,如果计数器达到0,则删除整行。我认为它可能看起来像这样,但我不知道这是否是有效的语法:
INSERT INTO WordsTable (word, counter)
VALUES('$word', 1)
ON DUPLICATE KEY UPDATE counter = counter + 1
有一个很好的干净方法吗?
谢谢!
答案 0 :(得分:1)
你需要做两个查询:
DELETE
FROM WordsTable
WHERE id='$deleteThisWord' AND counter = 1;
UPDATE WordsTable
SET counter = counter - 1
WHERE id = '$deleteThisWord'