insert into tablename
select 0,'123456' from tablename
where sign=1 and phone='123456';
解决方案 »
- 更新语句怎么写
- 触发器问题,这已经是第三次问了,高手拜托看看啊
- 急急急:MySQL中如何指定系统时间为时间字段的默认值?????
- 我的SQL语句,一运行就死机,急![每天至少一帖]
- Postgresql 中字段值自动增加,除了定义为serial之外,还有没有别的方法?
- 求一条语句,如何将一列中的数据按字母顺序排列?
- 请教高手:如何解决mysql数据库中data目录下日志文件增长太快的问题
- mysql 中连接的使用
- win7下mysql的数据文件默认在哪个目录存放
- 【求助】数据库检索分类性能问题
- 帮我看一下,我的show global status 有什么问题
- MySQL:子查询中存在两个不同值时报错,怎么办?
insert into test
select 0,'123456' from test
where sign=1 and phone='123456'
union all
select distinct 1,'123456' from test
where not exists(select 1 from test where sign=1 and phone='123456');
mysql> select * from t_floodow;
Empty set (0.00 sec)mysql> insert into t_floodow
-> select count(*)=0,'123456'
-> from t_floodow
-> where col1=1 and phone='123456';
Query OK, 1 row affected (0.06 sec)
Records: 1 Duplicates: 0 Warnings: 0-- 第一次,不存在 1,123456, 所以插入 | 1 | 123456 |
mysql> select * from t_floodow;
+------+--------+
| col1 | phone |
+------+--------+
| 1 | 123456 |
+------+--------+
1 row in set (0.00 sec)mysql> insert into t_floodow
-> select count(*)=0,'123456'
-> from t_floodow
-> where col1=1 and phone='123456';
Query OK, 1 row affected (0.08 sec)
Records: 1 Duplicates: 0 Warnings: 0-- 第二次,存在 1,123456, 所以插入 | 0 | 123456 |
mysql> select * from t_floodow;
+------+--------+
| col1 | phone |
+------+--------+
| 1 | 123456 |
| 0 | 123456 |
+------+--------+
2 rows in set (0.00 sec)mysql>
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html