SQL CASE的用法,比想象中的强大
表如下
一条语句显示所有大于25岁和下的人,以上的人显'大龄'
select case when age>25 then '大龄' else '小龄' end as 年龄级别,count(*) as 人数 from infor group by case when age>25 then '大龄' else '小龄' end
相关文档:
table a(id, type):
id type
----------------------------------
1 1
2 1
3 &n ......
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)
删除表:
Drop table [表 ......
--当前使用的数据库是 系统自带的 master
create database temp1
go --此处不加go的话下面use temp1 会报错:找不到存储过程 'temp1'。
use temp1
set xact_abort on
begin tran
create table [order]( --order是关键字必须用[ ];
id int
)
create table fOrder(
id int
)
-- 下面的操作主要是为了实现fO ......
做数据库开发或管理的人经常要创建大量的测试数据,动不动就需要上万条,如果一条一条的录入,那会浪费大量的时间,本文介绍了Oracle中如何通过一条SQL快速生成大量的测试数据的方法。
产生测试数据的SQL如下:
SQL> select rownum as id,
2 &nbs ......