Please help me.

请帮我。

select * from hoge where id=xxx; 

If there is a data, I do it to do it, but though I implement this step, there is if in a program, and insert hoge set data=0 is troublesome if update hoge set data=data+1, a result are 0 lines.

如果有数据,我这样做,但是虽然我实现了这一步,但是如果在程序中,并且插入hoge set data = 0很麻烦,如果更新hoge set data = data + 1,结果为0线。

May not you realize this procedure by a blow by SQL? replace hoge select id, data+1 as data from hoge where id = x; When it was this SQL, a result was not usable because data did not enter in the case of NULL.

你可能不是通过SQL的一击来实现这个程序吗?将hoge select id,data + 1替换为来自hoge的数据,其中id = x;当它是这个SQL时,结果不可用,因为在NULL的情况下没有输入数据。

After all will not there be it whether it is a plural number or a comb by SQL in an if sentence? If there is a simpler method, please teach it.

毕竟不会是if句子中的复数还是SQL的梳子?如果有更简单的方法,请教它。

People thanking you in advance.

人们提前感谢你。

2 个解决方案

#1


If I'm understanding the question properly (I don't think the OP is a native English speaker), you can use ON DUPLICATE KEY to do this in MySQL.

如果我正确理解了这个问题(我认为OP不是母语为英语的人),你可以使用ON DUPLICATE KEY在MySQL中执行此操作。

INSERT INTO table 
  (column1, column2, ...)
VALUES
  ('initial value for column1', 'initial value for column2', ...)
ON DUPLICATE KEY UPDATE
  column1 = column1 + 1, column2 = 'new value for column2';

更多相关文章

  1. 在Linux环境下,将Solr部署到tomcat7中,导入Mysql数据库数据, 定时更
  2. Jmeter—8 连接microsoft sql server数据库取数据
  3. 基于Sqlcipher和GreenDao的数据库加密
  4. 仅在SQL Server数据库中显示包含3个单词的名称
  5. 线程往数据库里插数据时偶尔会报错
  6. unity连接数据库MySQL简单例子
  7. 通过SQL语句访问远程数据库
  8. [SQL Server] 数据库日志文件自动增长导致连接超时的分析
  9. JSP连接Mysql的数据库连接池配置相关

随机推荐

  1. Python NameError:全局名称“Form”没有
  2. Hive中使用Python实现Transform时遇到Bro
  3. python学习笔记(3)--爬虫基础教程1
  4. 在NumPy中更改数组边缘的值
  5. 学习用pyhon写hive udf
  6. 创建单独的函数而不是一个大的缓慢处理时
  7. python打印系统所有tcp,udp监听端口及服
  8. python学习(13)————jieba进阶生成词云
  9. 用于搜索和替换大字符串的最快Python方法
  10. 基于scrapy框架的关于58同城招聘网站信息