ALTER TABLE test_tbl ADD test_no int;
ALTER TABLE recs ADD category_id1 int AFTER note;
応用例
yagisテーブルに新フィールドを追加する例ALTER TABLE `yagis` ADD `test_value` INT NULL DEFAULT '0' COMMENT 'テスト数値' AFTER `modified`;
ALTER TABLE `yagis` ADD `test_name` VARCHAR(256) CHARACTER SET utf16 COLLATE utf8mb4_general_ci NULL COMMENT 'テスト名' AFTER `test_value`;
ALTER TABLE `yagis` ADD `test_flg` TINYINT NULL DEFAULT '0' COMMENT 'test_flg' AFTER `test_name`;
ALTER TABLE `yagis` ADD `test_amt` DOUBLE NULL DEFAULT '0' COMMENT 'テスト金額' AFTER `test_flg`;
ALTER TABLE `yagis` ADD `test_date` DATE NULL COMMENT 'テスト日付' AFTER `test_amt`;
ALTER TABLE `yagis` ADD `datetime` DATETIME NULL COMMENT 'テスト日時' AFTER `test_date`;
ALTER TABLE `yagis` ADD `test_text` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT 'テストテキスト' AFTER `datetime`;
select aa_id, sum (sales) as sum_sales, sum (imp) as sum_imp, (sum (sales) / sum (imp)) as xxx from sales group by aa_id order by xxx desc
ALTER TABLE recs DROP create_date
SELECT
anim_id,COUNT (id) as cnt,
anim_id
FROM
animals
GROUP BY
anim_id
HAVING cnt > 1
SELECT
COUNT (id) as cnt,
anim_id
FROM
animals
WHERE COUNT (id) > 1
GROUP BY
anim_id
SELECT * FROM tests WHERE animal IS NULL
SELECT * FROM tests WHERE animal NOT IS NULL
SELECT * FROM tests WHERE animal = ''
SELECT * FROM tests WHERE animal != ''
SELECT * FROM tests WHERE (animal IS NULL OR animal = '')
SELECT * FROM tests WHERE animal IS NOT NULL AND animal != ''
SELECT * FROM tests WHERE
(
(title IS NOT NULL AND flg_a = 3)
OR
(title IS NULL AND flg_a = 4)
)
SELECT * FROM nekos WHERE id IN (1,4,6);
SELECT * FROM nekos WHERE id NOT IN (1,4,6);