我有一个包含两列的数据库表:
CREATE TABLE Main(Id TEXT, Count INTEGER)
我目前正在使用类似下面的代码来为列添加数字(如果它已经存在):
query = SELECT * FROM Main WHERE Id=some_word LIMIT 1
if(query has some elements){
UPDATE Main SET Count=query.count+word_count WHERE Id=some_word
}
else{
INSERT INTO table_name SELECT some_word AS Id , word_Count AS Count
//some more UNION SELECT ...
}
如何更快地完成这些陈述?