如何使用一条SQL语句同时在A表和B表中生成一条数据

WBOY
发布: 2024-01-25 09:00:06
转载
1035 人浏览过

如何使用一条SQL语句同时在A表和B表中生成一条数据

如何使用一条SQL语句同时在A表和B表中生成一条数据

使用循环语句,可以插入任意的数据。

参考代码:

delete from whilestu1;

commit;

DECLARE

num1 number;

maxstuid number;

age number;

birthday date;

begin

num1:=1;

WHILE num1--获取最大的stuid

select max(stuid)+1 into maxstuid from whilestu1;

if maxstuid is null then

maxstuid:=1;

end if;

birthday:=sysdate-ROUND(DBMS_RANDOM.VALUE(300,600),0);

age:=ROUND(DBMS_RANDOM.VALUE(18,40),0);

--插入数据

insert into whilestu1(stuid,stuName,age,birthday)

values (maxstuid,'学员'||cast(maxstuid as varchar2(50)),age,birthday);

commit;

num1:=num1+1;

END LOOP;

end;

/

SQL在查询结果中选取某一条数据

-- 用的啥数据库也不写清楚。。。

-- MS sql server2005以上,ORACLE

select * from (

select row_number() over ( order by starttime asc) as rownum,* from steriworkrecord where starttime between '2013-11-1' and '2013-12-31'

) a

where rownum between 2 and 10-- 【注意( order by starttime asc)是你排序的方式asc升序,desc降序】

========================================================

-- ORACLE还可以

select * from (

select rownum as n,* from steriworkrecord

where starttime between '2013-11-1' and '2013-12-31'

) a

where a.n between 2 and 10==========================================================

-- MYSQL,postgreSQL似乎只能标量子查询

SELECT *FROM (

SELECT a.*,(

SELECT count(*) FROM steriworkrecordb WHERE b.ID

from steriworkrecorda

) ts

where ts.n between 2 and 10

-- 【注意b.ID

-- 代码都忙你实际测试了ok

如何用SQL语句取出数据库中的特定一条数据

通过查询语句select * from user where id=1

我不知道你这个username指的是不是字段,如果是要取出表中某个字段的值。

可以通过select 字段名1,字段名2 ... from user where id=1。

-- MS sql server2005以上,ORACLE

select * from (

select row_number() over ( order by starttime asc) as rownum,* from steriworkrecord

where starttime between '2013-11-1' and '2013-12-31'

) a

where rownum between 2 and 10

-- 【注意( order by starttime asc)是你排序的方式asc升序,desc降序】

-- ORACLE还可以

select * from (

select rownum as n,* from steriworkrecord

where starttime between '2013-11-1' and '2013-12-31'

) a

where a.n between 2 and 10

-- MYSQL,postgreSQL似乎只能标量子查询

SELECT *FROM (

SELECT a.*,(

SELECT count(*) FROM steriworkrecordb WHERE b.ID

from steriworkrecorda

) ts

where ts.n between 2 and 10

-- 【注意b.ID

以上是如何使用一条SQL语句同时在A表和B表中生成一条数据的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:docexcel.net
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板