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.すべての音楽ファイルを取得しname列,length列を表示。レコードはランダム(重複あり)にソート。
select name, length from audio order by random
 
9.filetype"mp3"の音楽ファイルだけを取得し、name, filetype列を表示。
select name, filetype from audio where filetype = 'mp3'
 
10.lengthが300秒以上の音楽ファイルだけを取得し、name, length列を表示。
select name, length from audio where length >= 300
 
11.nameが"あ"で始まる音楽ファイルだけを取得し、name, length列を表示。
select name, length from audio where name like 'あ%'
 
12.releasedateに何らかのレコードが設定されている音楽ファイルだけを取得し、name, length, releasedate列を表示。
select name, length, releasedate from audio where releasedate isnot null
 
13.lastplayeddateが"2013/01/01 13:00:01"以降の動画ファイルを取得し、name, lastplayeddate列を表示。
select name, lastplayeddate from video where lastplayeddate >= '2013/01/01 13:00:01'
 
14.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'
 
15.playcountが10以上の音楽ファイルだけを取得し、playcount, name列を表示。レコードはplaycountで降順ソート。
select playcount, name from audio where playcount >= 10 order by playcount desc
 
16.playcountが5以上の音楽ファイルだけを取得し、name, playcount列を表示。レコードはplaycountで昇順、nameで降順ソート。
select playcount, name from audio where playcount >= 5 order by playcount, name desc
 
17.列に別名を付ける
select name as タイトル, length as 時間 from audio
 
18.すべての音楽ファイルを対象にlengthでソートし、先頭の10件取得しname列を表示。
select name from audio order by length option top 10
 
19.すべての音楽ファイルを対象にnameでソートし、2件目のレコードから5件取得しname列を表示。
select name from audio order by length option limit 1, 5
 
20.すべての音楽ファイルを対象にplaycountの多い順でソートし、上位25%のレコードを表示。(正確には025%の間のレコードを取得・表示)
select name, playcount from audio order by playcount desc option persent 0, 25
 
21.bから始まるタイトルの音楽ファイルを取得し、name列を表示。合計再生時間が1時間(3600)に収まるように先頭から絞り込む
select name, length from audio where name like 'b%' option totallength 3600
 
22.音楽ファイルを取得し、更にartist列のランダムな値をつかい、レコードを絞り込む。
select artist, title from audio option randomselectfrom artist
 
23.音楽ファイルを取得し、ジャンルからジャズを選択し、更にその中から、ランダムなアルバムを取得する。
select album, title from audio where genre='jazz' option randomselectfrom album
 
24.toStar関数を使い、自分の評価が☆3の検索を実行する。
select name, length, rating from audio where rating = toStar(3)
 
25.today系の関数を使い、最終再生日が5日前以降の検索する。
select name, lastplayeddate from audio where lastplayeddate >= TodayFirst(-5) order by lastplayeddate
 
26.CurrentValue関数を使い、現在再生中のメディアと同じ日以降にライブラリに追加したメディアを検索する。
select adddate, name from video where adddate >= CurrentValue() order by adddate, name
 
27.RandomValue関数を使い、genreからランダムな値を取得してメディアを検索する。
select name, album from audio where genre = RandomValue()
 
28.convert関数を使い、length列の出力結果を加工する。※「結果タブ出力」の場合のみ変換実施。
select name, length, convert(length) from audio option top 100
 
29.expandを使い、「ユーザ定義の再生リスト1」からデータ取得
select name, length expand 'ユーザ定義の再生リスト1'
 
30.expandを使い、「ユーザ定義の再生リスト1」「ユーザ定義の再生リスト2」からデータ取得
select name, length expand 'ユーザ定義の再生リスト1', 'ユーザ定義の再生リスト2'
 
31.expandを使い、現在再生中のプレイリストからデータ取得
select name, length expand current
 
32.expandを使い、SQL検索画面のプレイリストビューに設定されたプレイリストからデータ取得
select name, length expand playlistview
 
33.expandを使い、1番目のブックマークを含むプレイリストからデータ取得
select name expand bookmark1
 
34.expandを使い、スタックボードからデータ取得
select name, length expand stackboard
 
35.expandを使い、最近使ったファイルから表示件数だけデータ取得
select * expand recentfiles_mix
 
36.expandを使い、最近使ったファイルから全てのデータ取得
select * expand recentfiles_mix_all
 
37.expandを使い、最近再生頻度の高い音楽ファイルからデータ取得
select * expand frequentlyfiles_audio
 
38.expandを使い、最近再生頻度の高い動画ファイルからデータ取得
select * expand frequentlyfiles_video_all
 
 
最終更新:2016年12月30日 12:35