code225 -9ページ目

code225

WEBプログラミングのメモ。PHP、JavaScript、HTML、MySQLなど。

CASEを使うことで都道府県をコード表示してみる

都道府県は、テーブルのadd1フィールドに入っている前提。

ちょっとSQL文が長いがしょうがないでしょうか。


SELECT code,namej,add1,
CASE
when left(add1,2)='北海' then '01'
when left(add1,2)='青森' then '02'
when left(add1,2)='岩手' then '03'
when left(add1,2)='宮城' then '04'
when left(add1,2)='秋田' then '05'
when left(add1,2)='山形' then '06'
when left(add1,2)='福島' then '07'
when left(add1,2)='茨城' then '08'
when left(add1,2)='栃木' then '09'
when left(add1,2)='群馬' then '10'
when left(add1,2)='埼玉' then '11'
when left(add1,2)='千葉' then '12'
when left(add1,2)='東京' then '13'
when left(add1,2)='神奈' then '14'
when left(add1,2)='新潟' then '15'
when left(add1,2)='富山' then '16'
when left(add1,2)='石川' then '17'
when left(add1,2)='福井' then '18'
when left(add1,2)='山梨' then '19'
when left(add1,2)='長野' then '20'
when left(add1,2)='岐阜' then '21'
when left(add1,2)='静岡' then '22'
when left(add1,2)='愛知' then '23'
when left(add1,2)='三重' then '24'
when left(add1,2)='滋賀' then '25'
when left(add1,2)='京都' then '26'
when left(add1,2)='大阪' then '27'
when left(add1,2)='兵庫' then '28'
when left(add1,2)='奈良' then '29'
when left(add1,2)='和歌' then '30'
when left(add1,2)='鳥取' then '31'
when left(add1,2)='島根' then '32'
when left(add1,2)='岡山' then '33'
when left(add1,2)='広島' then '34'
when left(add1,2)='山口' then '35'
when left(add1,2)='徳島' then '36'
when left(add1,2)='香川' then '37'
when left(add1,2)='愛媛' then '38'
when left(add1,2)='高知' then '39'
when left(add1,2)='福岡' then '40'
when left(add1,2)='佐賀' then '41'
when left(add1,2)='長崎' then '42'
when left(add1,2)='熊本' then '43'
when left(add1,2)='大分' then '44'
when left(add1,2)='宮崎' then '45'
when left(add1,2)='鹿児' then '46'
when left(add1,2)='沖縄' then '47'
else '---'
END ken
FROM `table`
ORDER BY ken


tableの内容を簡単にグラフ化するjQueryプラグイン「gvChart」

http://www.skuare.net/2010/06/tablejquerygvchart.html



●1)gvChartファイルをダウンロード&設置。

●2)ヘッダー記述。

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery.gvChart.js"></script>
<script type="text/javascript">
gvChartInit();
$(document).ready(function(){
$('#id名').gvChart({
chartType: 'ColumnChart',
//その他に AreaChart、LineChart、BarChart、ColumnChart、PieChartがあります。
gvSettings: {
vAxis: {title: 'No of players'}, //縦軸タイトル
hAxis: {title: 'Month'}, //横軸タイトル
width: 720, //幅
height: 300, //高さ
}
});
</script>


●3)テーブルを記述。

テーブルの数値でない部分はthでしっかり囲むこと。

<table id="id名">
<caption>Game players count</caption>
<thead>
<tr>
<th></th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
</tr>
</thead>
<tbody>
<tr>
<th>2010</th>
<td>125</td>
<td>185</td>
<td>327</td>
<td>359</td>
</tr>
<tr>
<th>2009</th>
<td>1167</td>
<td>1110</td>
<td>691</td>
<td>165</td>
</tr>
</tbody>
</table>


ついthをtdで記述してしまったりするが、ちゃんとthで囲まないと表示されないので注意!


年度別にセミナーA、セミナーB、合計の人数を出したい場合、

CASEを使う





年度  A  B   計
---------------------
2011  350 200  550
2010  250 150  500
2009  125 120  245
2008  200 100  300




SELECT year_c,
SUM(CASE
WHEN seminar_c = 'A' THEN 1
ELSE 0
END
) as `A`,
SUM(CASE
WHEN seminar_c = 'B' THEN 1
ELSE 0
END
) as `B`,
SUM(CASE
WHEN seminar_c != '取消し' and seminar_c not in('A','B') THEN 1
ELSE 0
END
) as `計`
FROM `table`
GROUP BY year_c
ORDER BY year_c DESC

ダウンロードせず、Googleにリンクしたほうが簡単


cssは、テーマがいくつかあり、見た目が変更出来ます。


<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/blitzer/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>



jQueryやUI、PrototypeなどのライブラリーをGoogleライブラリAPIから読み込む方法
http://worldwidedeb.net/2011/05/09/jquery-ui-prototype-google-api-url


登録してみました

どんなもんでしょう



パソコンからメール送信で更新は出来ないようですね