SELECT DATE_FORMAT(test_date, '%Y-%m') as test_ym, COUNT(id) as count, SUM(sale_amount) as sum_sale_amount, FROM shops WHERE DATE_FORMAT(test_date, '%Y') = '2015' GROUP BY DATE_FORMAT(test_date, '%Y-%m') ORDER BY count
SELECT DATE_FORMAT(test_date, '%Y-%m') as test_ym, COUNT(id) as count, SUM(sale_amount) as sum_sale_amount, FROM shops WHERE DATE_FORMAT(test_date, '%Y') = '2015' GROUP BY DATE_FORMAT(test_date, '%Y-%m') ORDER BY id
SELECT * FROM animals WHERE status_id IN(2,3,NULL)
SELECT * FROM animals WHERE status_id IN(2,3) || status_id IS NULL
SELECT DATE_FORMAT(test_date, '%Y-%m') as test_ym, COUNT(*) as count, SUM(val1) FROM nekos GROUP BY DATE_FORMAT(test_date, '%Y-%m')
SELECT DATE_FORMAT(test_date, '%Y-%m') as test_ym, COUNT(*) as count, SUM(val1) FROM nekos GROUP BY DATE_FORMAT(test_date, '%Y-%m') ORDER BY count
SELECT DATE_FORMAT(test_date, '%Y') as test_y, COUNT(*) as count, SUM(val1) FROM nekos GROUP BY DATE_FORMAT(test_date, '%Y') ORDER BY count
select lpad(id,2,'0') from animals;例:3→03
select rpad(id,2,'0') from animals;例:3→30
/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '変更したパスワード';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';
SELECT * FROM animals WHERE created='2015-10-06'「2015-10-06」は「2015-10-06 00:00:00」と同じであるためである。
SELECT * FROM animals WHERE created >= '2015-10-06 00:00:00' AND created <= '2015-10-06 23:59:59'
SELECT * FROM animals WHERE created >= '2015-10-06' AND created < '2015-10-07'
SELECT * FROM animal WHERE CAST(price AS DECIMAL) = CAST(123.45 AS DECIMAL);
/* 構造コピー */ CREATE TABLE kanis LIKE nekos; /* データコピー */ INSERT INTO kanis SELECT * FROM nekos;
nekosテーブルをkanisテーブルとしてコピーする例
/* 構造コピー */ CREATE TABLE kanis LIKE nekos; /* データコピー */ INSERT INTO kanis(id, kani_name,value1) SELECT id,neko_name,value1 FROM nekos;
# 構造コピー
# parkデータベース・animalsテーブルの構造をpark2データベースへコピーする。
CREATE table park2.animals LIKE park.animals;
# データコピー
# parkデータベース・animalsテーブルのデータをpark2のanimalsテーブルへコピーする。
INSERT into park2.animals SELECT * from park.animals;
SHOW TABLES FROM cake_demo
SHOW FULL COLUMNS FROM animals