My SQL 関数
select * from 'address_t' where 'birthday' < '1980';
SQLではPHPとは違って数字でもコーテーションで囲む必要がある。
1980より以前に生まれた人を検索。80年代も含めた比較的にアバウトな検索には以下のようにlikeを使う。
select * from 'address_t' where 'birthday' like '198_%';
select name from address_t where address like '%shi%'
住所に「し」という文字が入っている名簿を検索。%を使う。
order by,asc or disc
select * from address_t order by birthday asc;
ソートする場合はorder by ascで誕生日の小さい順(上り順)に並び替える
select * from address_t order by birthday desc;
下り順の場合はこれ。ascとdescを入れ替えるだけ。
select * from address_t limit 0,3;
データの件数を絞り込む。返り値がゼロで三件目まで表示。
グループ化
select year(birthday),count(*) as num from address_t group by year(birthday);
データをグループに分けて分類する方法。numもSQLでは違った意味で使われているみたいだし、今後研究の余地あり。