日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

SQLZOO练习题(1)

發(fā)布時間:2024/1/18 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQLZOO练习题(1) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

SQLZOO練習題(1)

sqlzoo上較難的一些sql查詢練習題及其解題思路。

題目
Put the continents right…

  • Oceania becomes Australasia
  • Countries in Eurasia and Turkey go to Europe/Asia
  • Caribbean islands starting with ‘B’ go to North America, other Caribbean islands go to South America
    Show the name, the original continent and the new continent of all countries.

答案

select name, continent, casewhen continent='oceania' then 'Australasia'when continent in ('eurasia', 'turkey') then 'Europe/Asia'when continent='caribbean' then case when name like 'B%' then 'North America'else 'South America'endelse continentend from world order by name asc

思路
主要涉及case函數(shù)的用法。

當滿足condition1時,返回value1,滿足condition2,返回value2,都不滿足返回def_value。

該題解法在于使用一個case函數(shù)的嵌套。讓以B開頭的加勒比島國屬于北美,非B開頭的屬于南美。在父case when continent = ‘caribbean’ then后應(yīng)該填入需要返回的value。但是這里我們需要做一個判斷,所以再嵌套一個case,判斷when name like 'B%'時返回北美,否則返回南美。這樣經(jīng)過判斷后的北美和南美就作為子case返回的value傳遞給父case,填入到then后面的返回值中。

希望本文對你有所幫助。

總結(jié)

以上是生活随笔為你收集整理的SQLZOO练习题(1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。