SQL语句练习实例之九 ——对字符串进行排序
2011-11-22 23:24
579 查看
----对字符串进行排序
---对字符串DCCBBABA 执行之后变成 AABBBCCD
declare @str nvarchar(20)
set @str='DCCBBABA'
select replicate('A',(len(@str)-len(replace(@str,'A',''))))+
replicate('B',(len(@str)-len(replace(@str,'B','')))) +
replicate('C',(len(@str)-len(replace(@str,'C','')))) +
replicate('D',(len(@str)-len(replace(@str,'D',''))))
---电影院座位预订(未成功)
---电影院预定连号的座位号约束
--预订规则是两片连号的座位不能重叠
create table filmeSeat
(
reserver nvarchar(20) not null primary key
,startSeat int not null,
finishSeat int not null
)
go
insert filmeSeat
select '张三',1,4 union
select '李四',6,7 union
select '王五',21,24 union
select '赵六',11,14 union
select '钱七',16,18
go
drop table filmeSeat
--go
--create table filmeSeat
--(
--reserver nvarchar(20) not null primary key
--,startSeat int not null,
--finishSeat int not null,
--check(startSeat<=finishSeat))
--go
------在Check中不允许使用子查询。只允许使用标量表达式。
--ALTER TABLE filmeSeat
--ADD CONSTRAINT no_overlaps
--check(not exists (select t1.reserver from filmeSeat as t1
--where filmeSeat.startSeat between t1.startSeat and t1.finishSeat
--or filmeSeat.finishSeat between t1.startSeat and t1.finishSeat)
--)
----------
---对字符串DCCBBABA 执行之后变成 AABBBCCD
declare @str nvarchar(20)
set @str='DCCBBABA'
select replicate('A',(len(@str)-len(replace(@str,'A',''))))+
replicate('B',(len(@str)-len(replace(@str,'B','')))) +
replicate('C',(len(@str)-len(replace(@str,'C','')))) +
replicate('D',(len(@str)-len(replace(@str,'D',''))))
---电影院座位预订(未成功)
---电影院预定连号的座位号约束
--预订规则是两片连号的座位不能重叠
create table filmeSeat
(
reserver nvarchar(20) not null primary key
,startSeat int not null,
finishSeat int not null
)
go
insert filmeSeat
select '张三',1,4 union
select '李四',6,7 union
select '王五',21,24 union
select '赵六',11,14 union
select '钱七',16,18
go
drop table filmeSeat
--go
--create table filmeSeat
--(
--reserver nvarchar(20) not null primary key
--,startSeat int not null,
--finishSeat int not null,
--check(startSeat<=finishSeat))
--go
------在Check中不允许使用子查询。只允许使用标量表达式。
--ALTER TABLE filmeSeat
--ADD CONSTRAINT no_overlaps
--check(not exists (select t1.reserver from filmeSeat as t1
--where filmeSeat.startSeat between t1.startSeat and t1.finishSeat
--or filmeSeat.finishSeat between t1.startSeat and t1.finishSeat)
--)
----------
相关文章推荐
- SQL语句练习实例之十——SQL SERVER 行转列的性能测试
- Oracle 中文字段进行排序的sql语句
- 拼接字符串sql语句查询[WEB学习实例]
- SQL语句练习实例之五——WMS系统中的关于LIFO或FIFO的问题
- SQL语句练习实例之五 WMS系统中的关于LIFO或FIFO的问题分析
- SQL对字符串进行排序
- 按照查询结果中某列出现的次数进行排序的SQL语句
- SQL语句练习实例之七——剔除不需要的记录行
- SQL对字符串进行排序
- SQL语句练习实例之二——找出销售冠军
- SQL语句练习实例之三——平均销售等待时间
- SQL语句in进行排序
- SQL对字符串进行排序
- 一个计算数值并进行排序的SQL语句
- 字段中 字符串有条件连接 并分组显示,排序 用sql语句
- SQL语句中让数字型字段按字符进行排序
- MySQL批量替换指定字段字符串SQL语句及实例分析
- SQL语句练习实例之十——SQL SERVER 行转列的性能测试