地層を剥がす

声を失った人間の発声練習です

『スッキリわかるSQL入門 第2版』ドリル(題材A・LEVEL4)の答え

『スッキリわかるSQL入門 第2版』のドリルを解き、ひたすら答えを載せていくシリーズです。今回は題材A・LEVEL4。関数がまったく使いこなせていない……頑張るぞ!

 

34.

select 口座番号, 残高/1000 as 千円単位の残高
from 口座
where 残高 >= 1000000

 

35.

insert into 口座
values('0652281',  'タカギ ノブオ', '1', 100000+3000, '2018-04-01')

 insert into 口座
values('1026413', 'マツモト サワコ', '1', 300000+3000, '2018-04-02')

insert into 口座
values ('2239710', 'ササキ シゲノリ', '1', 1000000+3000, '2018-04-03')

 

36.

update 口座
set 残高 = (残高 - 3000) * 1.003
where 口座番号 = '0652281' or 口座番号 = '1026413' or 口座番号 = '2239710'

 

37.

select 口座番号, 更新日, 更新日 + 180 as 通帳期限日
from 口座
where 更新日 <= '2016-12-31'

 

38.

select 口座番号, concat('カ)'|| 名義) as 名義
from 口座
where 種別 = '3'

 

39.

select distinct 種別 as 種別コード,
case 種別 when '1' then '普通'
when '2' then '当座'
when '3' then '別段' end as 種別名
from 口座
order by 種別コード

 

40.

select 口座番号, 名義,
case when 残高 < 100000 then 'C'
when 残高 > 100000 and 残高 < 1000000 then 'B'
else 'A' end as 残高ランク
from 口座
order by 残高ランク

 

41.

select length(口座番号) as 口座番号の文字数, length(replace(名義, ' ', '')) as 名義の文字数, length(cast(残高 as varchar)) as 残高の文字数
from 口座

 

42.

select 名義
from 口座
where substring(名義, 1,5) like '%カワ%'

 

43.

select 残高
from 口座
where length(cast(残高 as varchar)) >= 4
and substring(cast(残高 as varchar), length(cast(残高 as varchar))-2, 3) = '000'

 

44.

select 口座番号, 残高, trunc(残高 * 1.002, 0) as 利息
from 口座
order by 残高 desc

 

45.

select 口座番号, 残高,
case when 残高 < 500000 then trunc(残高 * 1.0001,0)
when 残高 >= 500000 and 残高 < 2000000 then trunc(残高 * 1.0002,0)
when 残高 >= 2000000 then trunc(残高 * 1.0003,0) end as 残高別利息
from 口座
order by 残高別利息 desc, 口座番号

 

46.

insert into 口座
values('0351262','イトカワ ダイ', '2',635110,current_date)

 

insert into 口座
values('1015513', 'アキツ ジュンジ','1',88463,current_date)

 

insert into 口座
values('1739298', 'ホシノ サトミ','1',704610,current_date)

 

47.

select 口座番号, 名義, 種別, 残高,
substring(cast(更新日 as varchar), 1, 4) || '年' ||
substring(cast(更新日 as varchar), 6, 2) || '月' ||
substring(cast(更新日 as varchar), 9, 2) || '日' as 更新日
from 口座
where 更新日 >= '2018-01-01' 

 

48.

select coalesce(cast(更新日 as varchar), '設定なし') as 更新日
from 口座
order by 更新日