A SQL to insert continuous values
I need a table to store all the working days. I dont like loop, so I tried sql. The following is the SQL I used.
insert into tb_working_days(data_date,day_type)
select DATE_ADD(data_date,INTERVAL (select count(1) from tb_working_days) day),"W"
from tb_working_days ;
At first, I insert one date into the table.
Then I run this sql once, I get two rows. Run once more, I get four rows, as so on.
after 10 runs, I get more than 1000 rows. the work is done.
The most interesting point is the sql after Interval, and it makes the magic. The db is smart enough to convert a set into a int. that is amazing.
A SQL to insert continuous values的更多相关文章
- sql动态insert向varchar(MAX)中写入据的问题
sql动态insert向varchar(MAX)中写入据的问题,在写入时出现列无效.后来发现,varchar要加''两个,号才可以 SET @SQL='INSERT INTO '+@TabName+' ...
- SQL Server Insert操作中的锁
原文:SQL Server Insert操作中的锁 这篇博文简单介绍一下在SQL Server中一条Insert语句中用到的锁. 准备数据 首先我们建立一张表Table_1,它有两列Id(bigint ...
- ORA-00913错误:PL/SQL: ORA-00913: too many values
ORA-00913错误 描写叙述:PL/SQL: ORA-00913: too many values 目标:编写一个能够循环插入数据的脚本 操作过程: SQL> desc tcustmer N ...
- Delphi X10.2 + FireDAC 使用 SQL 语句 INSERT
// CREATE TABLE [tabusers]( // [id] INTEGER PRIMARY KEY AUTOINCREMENT, // [username] CHAR NOT NULL, ...
- Mybatis执行sql(insert、update、delete)返回值问题
数据库:Mysql 在使用mybatis的过程中对执行sql的返回值产生疑问,顺手记录一下. 结论: insert: 插入n条记录,返回影响行数n.(n>=1,n为0时实际为插入失败) up ...
- sql学习--insert
insert的四种插入方式 第一种最简单的 into 和目标列的列表是可选的 intsert [into] tableA [(col1,col2)] values(val1,val2) 第二种 ins ...
- sql在insert时判断有无唯一性冲突
sql在insert时判断有无唯一性冲突,存在相同主键或唯一索引,则不创建 INSERT INTO table(field1, field2, fieldn) SELECT 'field1', 'fi ...
- sql server insert values 多值 与oracle 的不同
类似的语句在 oracle 中是不能执行的 insert into temp_tbl values('app'),('demo'); 但是在sql server 中是可以的 insert into c ...
- FMDB存储模型对象(以二进制存储)用NSKeyedArchiver archivedDataWithRootObject序列号,NSKeyedUnarchiver unarchiveObjectWithData反序列化(重点坑是sql语句@"insert into t_newsWithChannel (nwesName,newsType) values (?,?)")一定要用占位符
交友:微信号 dwjluck2013 一.封装FMDB单例 (1)JLFMDBHelp.h文件 #import <Foundation/Foundation.h> #import < ...
随机推荐
- avg(xxxxxx)什么时候能独自出现?
avg(xxxxxx)是作为求一组数据的平均数,需要有这组数据的总数和个数,所以通常配合着group by来使用, 比如: SELECT ID, AVG(GRADE) AS 平均数 FROM TEST ...
- Element div is not closed
报错内容:Element div is not closed 解决方法: 将代码复制到NotePad++.SubLime Text等文本编辑器中,另存为.jsp或者.html文件. 这样可以利用语法高 ...
- css3自定义placeholder字体颜色
::-webkit-input-placeholder{color:#f00;} ::-moz-placeholder{color:#f00;} :-moz-placeholder{color:#f0 ...
- Educational Codeforces Round 58
D. GCD Counting 题意: 给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1 题解: gcd>1的一定不会有很多.所以暴力搞一下就行,不需要点 ...
- client / server端用户的登录
# 客户端 import socket import hashlib import json import os import struct sk = socket.socket() # 实例化 sk ...
- 不同的路径12障碍物 · Unique Paths12
[抄题]: 有一个机器人的位于一个 m × n 个网格左上角. 机器人每一时刻只能向下或者向右移动一步.机器人试图达到网格的右下角. 问有多少条不同的路径? [思维问题]: 以为要用count来计数: ...
- MongoDB的数据类型(四)
JSON JSON是一种简单的数据表示方式,它易于理解.易于解析.易于记忆.但从另一方面来说,因为只有null.布尔.数字.字符串.数组和对象这几种数据类型,所以JSON有一定局限性.例如,JSON没 ...
- NPOI创建doc
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 配置springMVC
1.web.xml 前端控制器 配置规则:*.do: 拦截请求路径所有的后缀为.do;/* : 拦截所有, .jsp页面也会拦截; 不会使用此配置, 因为视图会无法跳转;/ : 拦截所有, .jsp页 ...
- [PHP] constant variable
print: 3.13 PI 3.14