SQL语句笔记,增加一个字段,统计该表内的数据信息
2008-03-28 17:23
543 查看
实例一
表结构:填空选择题选项 (subjectid,id2,optionid,optioncontent,rightkey)
依次对应内容:题号id,空项位置,每空选项号,选项内容,对或错
现在要加一个字段tabnum,统计每到题的选项个数
代码如下
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
create table #itmpfillchoicetabnum(subjectid varchar(75) null,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
tabnum int )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
insert into #itmpfillchoicetabnum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select subjectid,count(*)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
from 程序填空选择题选项
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
group by subjectid
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
--select *
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
--from #itmpfillchoicetabnum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select X.subjectid,X.id2,X.optionid,X.optioncontent,X.rightkey,Z.tabnum into #result
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
from 程序填空选择题选项 as X,#itmpfillchoicetabnum as Z
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
where X.subjectid = Z.subjectid
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
drop table 程序填空选择题选项
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select * into 程序填空选择题选项 from #result
实例二
在一张表里增加一个字段,并且该字段,依次用1,2,3,......赋值
代码
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select * , id = identity(int,1,1) into #tmp2 from iiresult
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
drop table iiresult
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select * into iiresult from #tmp
表结构:填空选择题选项 (subjectid,id2,optionid,optioncontent,rightkey)
依次对应内容:题号id,空项位置,每空选项号,选项内容,对或错
现在要加一个字段tabnum,统计每到题的选项个数
代码如下
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
create table #itmpfillchoicetabnum(subjectid varchar(75) null,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
tabnum int )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
insert into #itmpfillchoicetabnum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select subjectid,count(*)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
from 程序填空选择题选项
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
group by subjectid
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
--select *
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
--from #itmpfillchoicetabnum
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select X.subjectid,X.id2,X.optionid,X.optioncontent,X.rightkey,Z.tabnum into #result
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
from 程序填空选择题选项 as X,#itmpfillchoicetabnum as Z
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
where X.subjectid = Z.subjectid
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
drop table 程序填空选择题选项
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select * into 程序填空选择题选项 from #result
实例二
在一张表里增加一个字段,并且该字段,依次用1,2,3,......赋值
代码
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select * , id = identity(int,1,1) into #tmp2 from iiresult
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
drop table iiresult
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
select * into iiresult from #tmp
相关文章推荐
- 【ORACLE】一个简单实用的对数据进行行列转换并统计的SQL语句
- 用sql命令修改数据表中的一个字段为非空(not null)的语句
- 用sql语句怎么知道一个表的字段信息--------db2
- 在数据表中添加一个字段的SQL语句怎么写
- sql server 查询表信息,字段,数据类型的sql语句
- 【ORACLE】一个简单实用的对数据进行行列转换并统计的SQL语句
- 数据表中有字段time(类型为varchar),如何通过sql语句找出这个字段里力离当前最近的一个日期
- 用sql命令修改数据表中的一个字段为非空(not null)的语句
- SQL语句-统计全部数据,过滤掉其中两个字段同时重复的记录
- Oracle的小笔记,模糊处理人名,电话,地址之类字段数据时可以使用的SQL语句
- SQL语句增加虚拟字段,并根据情况显示不同的数据。。。(已阅。。。未阅。。)
- sql语句(一)统计跟单位目录关联的人员信息表的多个数据
- ListUI中增加了分录的字段后,query中的sql语句显示出来的是按照顺序显示出来的,而ListUI中显示出来的数据确实乱的
- mysql命令行命令和SQL语句,MySQL修改删除增加字段类型,字段数据等。。
- sql语句 一个字段有好多重复的数据,但只取第一次填进去的数据
- Mysql 根据一个表数据更新另一个表的某些字段(sql语句)
- 一个sql语句同时实现两条数据的某个字段值交换
- 给定一个一oracle建表的sql语句,解析读出的字符串,将表名、字段名、字段类型数据取出,怎么实现啊?
- SQL语句获取数据表名,字段等信息
- mysql语句 一个表统计每天产生的不同类型数据 根据类型字段 统计每天有多少