SQL语句练习实例之九 ——对字符串进行排序
----对字符串进行排序
---对字符串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)
--)
----------
相关文章
- IntelliJ IDEA终于支持对Redis 的可视化窗口操作了,真香!
- 如何实现一个 Kubernetes CSI Driver
- springbootdruidmybatismysql多数据源事务管理
- MySql大小写配置
- Redis集群搭建
- 传统Spring配置JTA 实现多数据源事务的统一管理
- Oracle定时任务
- Oracle查看锁表和解锁
- Mybatis resultMap和resultType的区别
- WebService如何封装XML请求 以及解析接口返回的XML
- Maven手动将jar导入本地仓库
- 初入SG-UAP
- sg-uap常用注解介绍
- Docker 阿里云镜像加速
- Elasticsearch 读时分词、写时分词
- SecureFX中文目录乱码问题解决方案
- 分布式事务
- 分布式CAP定理
- MySQL5.5安装教程
- Oracle数据库之FORALL与BULK COLLECT语句