随笔分类 - SQL
摘要:如下SQL的优化: select count(*) from ( select id,name,col1,col2 from t1 where name='xxxx' union select id,name ,null as col1,'' as col2 from t2 where id!=1
阅读全文
摘要:通常数据库的优化从硬件层面去考虑可分为4个方面: CPU:即降低计算复杂度,如减少sql各类聚合函数,窗口函数,case when等。 IO :(较少查询结果集过程中对数据的访问量。数据优化很大程度从这里入手 网络 : 较少查询结果集的大小,去除不必要的查询字段 数据库资源 : 这里讲的数据库资源主
阅读全文
摘要:空座位: 一个餐厅1000个座位,用1000行,一行一个整数、一个字符(描述位置的地址)来存储数据。要求管理这个餐厅的座位,方便查找出空座位。并且按照起始和结束座位号分为几个片区。即空座位号的起始和结束分为多少个空座位片区。 解惑1:在座位号加上正负号,正号代表空座位,负号代表已经入座。 updat
阅读全文
摘要:双重身份问题: create table role_tab ( person char(5) not null, role char(1) not null ) insert into role_tab values('smith','O'),('smith','D'),('niu','O'),('
阅读全文
摘要:有表格存放每个顾客拥有的票。现在想查看哪些顾客的票不是连号,即有间隔。并找出间隔的开始与结束数字。 create table tickets ( buyer_name char(5) not null, ticket_nbr int default 1 not null check (ticket_
阅读全文
摘要:合并时间段: 将连续或者重叠的时间段合并。 create table timesheets ( task_id char(10) not null primary key, startdate date not null, enddate date not null, check(startdate
阅读全文
摘要:数据岛问题: 有表: create table dataisland (id int) insert into dataisland values(1),(2),(3),(7),(11),(12),(13) create table dataisland (id int) insert into d
阅读全文

浙公网安备 33010602011771号