SQLサンプル(旧)

SQLサンプル

// 1.すべての音楽ファイルを取得しname列を表示。
select name from audio

// 2.すべての動画ファイルを取得しname列,width列,height列を表示。
select name, width, height from video

// 3.すべての音楽ファイルを取得し、組み込み列(name,length,album,playcount等)を表示。
select * from audio

// 4.すべての音楽ファイルを取得しname列,length列を表示。レコードはnameで昇順ソート。
select name, length from audio order by name asc

// 5.すべての音楽ファイルを取得しname列,length列を表示。レコードはnameで降順ソート。
select name, length from audio order by name desc

// 6.すべての音楽ファイルを取得しalbum列,name列,length列を表示。レコードはalbumで昇順、nameで降順ソート。
select album, name, length from audio order by album asc, name desc

// 7.すべての音楽ファイルを取得しname列,length列を表示。レコードはランダムにソート。
select name, length from audio order by shuffle

// 8.filetypeが"mp3"の音楽ファイルだけを取得し、name, filetype列を表示。
select name, filetype from audio where filetype = 'mp3'

// 9.lengthが300秒以上の音楽ファイルだけを取得し、name, length列を表示。
select name, length from audio where length >= 300

// 10.nameが"あ"で始まる音楽ファイルだけを取得し、name, length列を表示。
select name, length from audio where name like 'あ%'

// 11.releasedateに何らかのレコードが設定されている音楽ファイルだけを取得し、name, length, releasedate列を表示。
select name, length, releasedate from audio where releasedate isnot null

// 12.lastplayeddateが"2013/01/01 13:00:01"以降の動画ファイルを取得し、name, lastplayeddate列を表示。
select name, lastplayeddate from video where lastplayeddate >= '2013/01/01 13:00:01'

// 13.nameが"あ"で始まり、かつlastplayeddateが"2013/01/01 13:00:01"以降の音楽ファイルだけを
// 取得し、name, length列を表示。
select name, length from audio where name like 'あ%' and lastplayeddate >= '2013/01/01 13:00:01'

// 14.playcountが10以上の音楽ファイルだけを取得し、playcount, name列を表示。レコードはplaycountで降順ソート。
select playcount, name from audio where playcount >= 10 order by playcount desc

// 15.playcountが5以上の音楽ファイルだけを取得し、name, playcount列を表示。レコードはplaycountで昇順、nameで降順ソート。
select playcount, name from audio where playcount >= 5 order by playcount, name desc

// 16.列に別名を付ける
select name as タイトル, length as 時間 from audio

// 17.すべての音楽ファイルを対象にlengthでソートし、先頭の10件取得しname列を表示。
select name from audio order by length option top 10

// 18.すべての音楽ファイルを対象にnameでソートし、2件目のレコードから5件取得しname列を表示。
select name from audio order by length option limit 1, 5

// 19.bから始まるタイトルの音楽ファイルを取得し、name列を表示。合計再生時間が1時間(3600秒)に収まるように先頭から絞り込む
select name, length from audio where name like 'b%' option totallength 3600

// 20.音楽ファイルを取得し、更にartist列のランダムな値をつかい、レコードを絞り込む。
select artist, title from audio option randomselectfrom artist

// 21.toStar関数を使い、自分の評価が☆3の検索を実行する。
select name, length, rating from audio where rating = toStar(3)

// 22.today系の関数を使い、最終再生日が5日前以降の検索する。
select name, lastplayeddate from audio where lastplayeddate >= TodayFirst(-5) order by lastplayeddate

// 23.CurrentValue関数を使い、現在再生中のメディアと同じ日以降にライブラリに追加したメディアを検索する。
select adddate, name from video where adddate >= CurrentValue() order by adddate, name

// 24.RandomValue関数を使い、genreからランダムな値を取得してメディアを検索する。
select name, album from audio where genre = RandomValue()

// 25.convert関数を使い、length列の出力結果を加工する。※「結果タブ出力」の場合のみ変換実施。
select name, length, convert(length) from audio option top 100

// 26.expandを使い、「ユーザ定義の再生リスト1」からデータ取得
select name, length expand 'ユーザ定義の再生リスト1'

// 27.expandを使い、「ユーザ定義の再生リスト1」「ユーザ定義の再生リスト2」からデータ取得
select name, length expand 'ユーザ定義の再生リスト1', 'ユーザ定義の再生リスト2'

// 28.expandを使い、現在再生中のプレイリストからデータ取得
select name, length expand current

// 29.expandを使い、SQL検索画面のプレイリストビューに設定されたプレイリストからデータ取得
select name, length expand playlistview

// 30.expandを使い、1番目のブックマークを含むプレイリストからデータ取得
select name expand bookmark1

// 31.expandを使い、スタックボードからデータ取得
select name, length expand stackboard

最終更新:2014年11月12日 00:39