読者です 読者をやめる 読者になる 読者になる

SQLで色々計算する小技

小技

なんとかごとの合計/集計/平均

SELECT nantoka,SUM(numbmer) FROM table GROUP BY nantoka ORDER BY nantoka;
SELECT nantoka,COUNT(numbmer) FROM table GROUP BY nantoka ORDER BY nantoka;
SELECT nantoka,AVG(numbmer) FROM table GROUP BY nantoka ORDER BY nantoka;

EXCELのVLOOKUPみたいな方法

UPDATE table1 INNTER JOIN table2 ON table1.field1 = table2.field1 SET table1.field2 = table2.field2;
UPDATE table1 INNTER JOIN table2 ON table1.field1 = table2.field1
    INNTER JOIN table3 ON table1.field3 = table3.field3
    SET table1.field2 = table2.field2, table1.field4 = table3.field4;

EXCELの重複を削除みたいな方法

SELECT DISTINCT(field) FROM table;