MySQL�R�}���h�E���ꗗ
-
�f�[�^�x�[�XMySQL�ŃT�|�[�g����Ă���SQL�R�}���h�̈ꗗ���f�ڂ��Ă��܂��B SQL�ꗗ�\�́A�e���ڂł̕��בւ����\�ł��B �f�[�^���얽�߁iDML�j�A�f�[�^��`���߁iDDL�j�A�g�����U�N�V�����A���Z�q�A���ɕ��ނ��Ă��܂��B �\�́utable_name�v�̓e�[�u�����A�uitem�v�͍��ڂ��Ӗ����܂��B �Ȃ��A���̃f�[�^�x�[�X�iOracle�ADB2���j�ł́ASQL�̏������قȂ邱�Ƃ�����܂��̂ŁA�����ӂ��������B
MySQL�́A���E�ōł��L���ȃI�[�v���\�[�X�E�f�[�^�x�[�X�Ƃ��Ēm���Ă���A���E�̃f�[�^�x�[�X�s��ł͑���PostgreSQL�Ȃǂ̃��C�o�������|���Ă��܂��B �I�[�v���\�[�X�E�f�[�^�x�[�X�ł��邽�߁A�قƂ�ǂ������^���T�[�o�[�ŗ��p�\�ɂȂ��Ă��܂��B
SQL ���� �Ӗ� �g�p�� ���� SELECT DML �f�[�^�s���擾 SELECT * FROM table_name table_name�̑S��A�S�s���擾 DISTINCT DML �d������s������ SELECT DISTINCT item FROM table_name table_name��item�����d���l����菜���Ď擾 AS DML �ʖ��̎w�� SELECT item1 AS item2 FROM table_name item1���item2��Ƃ����ʖ���t���Č��ʂ��擾 FROM DML �Ώۃe�[�u���w�� SELECT * FROM table_name table_name�̑S��A�S�s���擾 WHERE DML ���o�����̎w�� SELECT * FROM table_name WHERE item = 100 item��100�Ɠ������s���擾 GROUP BY DML �O���[�v�� SELECT COUNT(*) FROM table_name GROUP BY item table_name��item��̒l�ɂ���ăO���[�v�����A���̍s�����W�v HAVING DML �W�v���̌��ʂ𒊏o�����Ɏw�� SELECT x,SUM(i) FROM table_name GROUP BY x HAVING SUM(i) > 100 �O���[�v�̍��v�l��100�ȏ�ł���O���[�v�݂̂��擾 ORDER BY DML �擾�����E�\�[�g SELECT * FROM table_name ORDER BY item ASC table_name��item��̏����iDESC�͍~���j�ɕ��ѕς��� LIMIT DML ���ʂ̐��� SELECT * FROM table_name LIMIT 5,3 table_name�S�̂�5�s�ڂ���3�s�݂̂��擾 INSERT DML �f�[�^�s�̒lj� INSERT INTO table_name VALUES(1,2,'test') table_name�ɗ�̍�����1,2,'test'��ێ�����s��lj��iVALUES�ɑ����l�ƑΉ��j UPDATE DML �f�[�^�s�̍X�V UPDATE table_name SET item1 = 1 WHERE item2 = 2 table_name�ɂ����āAitem2��2�̃f�[�^�s��item1���1�ɍX�V DELETE DML �f�[�^�s�̍폜 DELETE FROM table_name WHERE item = 1 table_name�ɂ����āAitem��1�̍s�݂̂��폜 BEGIN �g�����U�N�V���� �g�����U�N�V�����J�n BIGIN WORK COMITT�����Ċm�肷��܂ŁAINSERT�ADELETE�AUPDATE�����f����Ȃ� COMMIT �g�����U�N�V���� �g�����U�N�V�������R�~�b�g COMMIT INSERT�ADELETE�AUPDATE�f���� ROLLBACK �g�����U�N�V���� �g�����U�N�V������߂� ROLLBACK INSERT�ADELETE�AUPDATE���j������ABIGIN�����s����O�̏�Ԃɖ߂� LOCK TABLES �g�����U�N�V���� �e�[�u���̃��b�N LOCK TABLES table_name READ �e�[�u����READ���b�N�iREAD/READ LOCAL/WRITE�j UNLOCK TABLES �g�����U�N�V���� �e�[�u���̃��b�N���� UNLOCK TABLES �S�e�[�u���̃��b�N������ CREATE TABLE DDL �e�[�u���̍쐬 CREATE TABLE table_name(item1 INTEGER, item2 VARCHAR(20)) item1��item2�̗�������A���ꂼ��̌^�������A������ł���table_name���쐬 NOT NULL DDL NOT NULL���� CREATE TABLE table_name(item1 INTEGER NOT NULL, item2 VARCHAR(20) NULL) item1���NOT NULL�Ɏw��Aitem2���NULL�w�� UNIQUE DDL UNIQUE���� CREATE TABLE table_name(item INTEGER UNIQUE) item1���UNIQUE�����ݒ� PRIMARY KEY DDL PRIMARY KEY���� CREATE TABLE table_name(item INTEGER NOT NULL PRIMARY KEY) item1���NOT NULL����� PRIMARY KEY�����ݒ� DROP TABLE DDL �e�[�u���̍폜 DOROP TABLE table_name table_name���폜 ALTER TABLE DDL �e�[�u�������ύX ALTER TABLE table_name ADD COLUMN item INTEGER item��𐔒l�^��table_name�ɒlj��iDROP�͍폜�j TRUNCATE TABLE DDL �e�[�u���S�s�폜 TRUNCATE TABLE table_name table_name�S�s�������ō폜�iDELETE��葬���j CREATE INDEX DDL �C���f�b�N�X�쐬 CREATE INDEX idx ON table_name table_name�ɑ��ăC���f�b�N�Xidx���쐬 DROP INDEX DDL �C���f�b�N�X�폜 DROP INDEX idx ON table_name table_name�ɑ��ăC���f�b�N�Xidx���폜 GRANT DDL �����̕t�^ GRANT ALL PRIVILEGES ON *.* TO name@localhost FLUSH PRIVILEGES ���ׂĂ̌�����localhost�̃��[�U�[name�ɃO���[�o�������Ƃ��ĕt�^ REVOKE DDL �����̔��D REVOKE ALL PRIVILEGES ON table_name FROM name FLUSHI PRIVILEGES table_name�ɑ��āA�S�Ă̌�����name�����D RENAME DDL �I�u�W�F�N�g���̕ύX RENAME table_nameA TO table_nameB �f�[�^�x�[�Xtable_nameA��table_nameB�Ƀ��l�[�� AND ���Z�q ���� SELECT * FROM table_name WHERE item1 = 100 AND item2 = 200 item1��100�Ɠ������A����item2��200�Ɠ������s��S�Ď擾 BETWEEN ���Z�q �͈͎w�� SELECT * FROM table_name WHERE �N�� BETWEEN 30 AND 40 �N���20�ȏ�A30�ȉ��̍s��S�Ď擾 IN ���Z�q �܂� SELECT * FROM table_name WHERE item IN (100,200) item��100��200�̍s��S�Ď擾 LIKE ���Z�q �p�^�[���}�b�` SELECT ���� FROM table_name WHERE ���� LIKE '%�Y' �����̍Ōオ�u�Y�v�ł���s��S�Ď擾 NOT ���Z�q �ے� SELECT * FROM table_name WHERE NOT item = 1 table_name��item��1�ł͂Ȃ��s��S�Ď擾 OR ���Z�q �܂��� SELECT * FROM table_name WHERE item1 = 100 OR item2 = 200 item1��100�A�܂���tem2��200�Ɠ������s��S�Ď擾 IS NULL ���Z�q NULL�l�̔��� SELECT * FROM table_name WHERE item IS NULL item��NULL�̍s��S�Ď擾 IS NOT NULL ���Z�q NULL�l�̔��� SELECT * FROM table_name WHERE item IS NOT NULL item��NULL�ł͂Ȃ��s��S�Ď擾 AVG ���i�W�v�j ���� SELECT AVG(DISTINCT item) FROM teble_name item��̏d���������ĕ��ϒl���v�Z COUNT ���i�W�v�j �s�����W�v SELECT COUNT(DISTINCT item)�@FROM table_name item��̏d���������čs�����v�Z MAX ���i�W�v�j �ő�l SELECT MAX(item) FROM table_name item��̍ő�l���v�Z MIN ���i�W�v�j �ŏ��l SELECT MIN(item) FROM table_name item��̍ŏ��l���v�Z STDDEV ���i�W�v�j �W���� SELECT STDDEV(item) FROM�@table_name item��̕W�������v�Z SUM ���i�W�v�j ���v�l SELECT SUM(item) FROM table_name item��̍��v�l���v�Z ASCLL ���i�����j �����R�[�h�ϊ� SELECT ASCALL(item) FROM teble_name item���ASCALL�ɂ�蕶���R�[�h�ɕϊ� CHAR ���i�����j �����ϊ� SELECT CHAR(item) FROM teble_name item���CHAR�ɂ�蕶���ɕϊ� CONCAT ���i�����j ������ SELECT CONCAT(item1,item2,item3) FROM table_name CONCAT�ɂ��A��item1,item2,item3���� INSERT ���i�����j ������̑}�� SELECT INSERT(item,5,1,'xyz') FROM table_name item���5�����ڂ���1������xyz�ɒu�� INSTER ���i�����j ������ SELECT INSTER(item1,item2) FROM table_name item1��̕������當����item2������ LENGTH ���i�����j �������擾 SELECT LENGTH(item) FROM table_name item��̕������v�Z CHARACTER
_LENGTH���i�����j �����擾 SELECT CHAR_LENGTH(item1) FROM table_name WHERE item2 = 100 table_name��item2��100�Ɠ������s����Aitem1��̕�����̒������擾 OCTET
_LENGTH���i�����j �������擾 SELECT OCTET_LENGTH(item) FROM table_name item��̃o�C�g�����v�Z POSITION ���i�����j ������ SELECT POSITION(item1 IN item2) FROM table_name item2��̕�������item1�̕�������������A�ŏ���item1�������ʒu���擾 REPEAT ���i�����j �J��Ԃ� SELECT REPEAT(item1,item2) FROM table_name item1��item2��J��Ԃ�����������擾 REPLACE ���i�����j �u�� SELECT REPLACE(item1,item2,item3) FROM table_name item1��̕�����item2��̕�����Ɠ������ӏ���S�ĕ�����item3�ɒu�� REVERSE ���i�����j ���] SELECT REVERSE(item) FROM table_name item��̕�����]������������擾�i1�o�C�g�����̂ݑΉ��j SUBSTRING ���i�����j �������o SELECT SUBSTRING(item1,item2,item3) FROM table_name item1��̕������item2�Ԗڂ���Aitem3�Ԗڂ܂ł𒊏o���Ď擾 RIGHT ���i�����j �E�������擾 SELECT RIGHT(item1,item2) FROM table_name item1��̕������item2��̒l�������A�E�����璊�o������������擾 LEFT ���i�����j ���������擾 SELECT LEFT(item1,item2) FROM table_name item1��̕������item2��̒l�������A�������璊�o������������擾 RTRIM ���i�����j �E�̋폜 SELECT RTRIM(item) FROM table_name item��E���̋���菜�� LTRIM ���i�����j ���̋폜 SELECT LTRIM(item) FROM table_name item�獶���̋���菜�� TRIM ���i�����j �w�蕶���̍폜 SELECT TRIM(item1 FROM item2) FROM table_name item2�̗��[����item1����菜�������ʂ��擾 INITCAP ���i�����j �擪��啶���ϊ� SELECT INITCAP(item) FROM teble_name item��̕������擪�����A�啶���ɕϊ� LOWER ���i�����j �������ϊ� SELECT LOWER(item) FROM table_name item��̕������S�ď������ɕϊ�������������擾 UPPER ���i�����j �啶���ϊ� SELECT UPPER(item) FROM table_name item��̕������S�đ啶���ɕϊ�������������擾 SYSDATE ���i���t�j ���ݓ��t SELECT STSDATE FROM DUAL ���݂̓������擾 CURRENT
_DATE���i���t�j ���ݓ��t SELECT CURRENT_DATE ���݂̓������擾 CURRENT
_TIME���i���t�j ���ݎ��� SELECT CURRENT_TIME ���݂̎������擾 CURRENT
_TIMESTAMP���i���t�j ���ݓ��� SELECT CURRENT_TIMESTAMP ���݂̓������擾 NOW ���i���t�j ���ݓ��� INSERT INTO table_name VALUES(NOW()) ���݂̓����ōs��lj� DATE
_FORMAT���i���t�j ���t�̐��` SELECT DATE_FORMAT(item,'%Y/%m/%d') FROM table_name item��iYYYY-MM-DD�`���j��YYYY/MM/DD�`���ɐ��` TIME
_FORMAT���i���t�j �����̐��` SELECT TIME_FORMAT(item,'%H:/%i:/%s') FROM table_name item��ihhmmss�`���j��hh:mm:ss�`���ɐ��` DATE
_ADD���i���t�j ���t�̉��Z DATE_ADD(item, INTERVAL 10 DAY) FROM table_name ���t�^��item���10������v�Z���Ď擾 DATE
_SUB���i���t�j ���t�̌��Z DATE_SUB(item, INTERVAL 10 DAY) FROM table_name ���t�^��item���10���O���v�Z���Ď擾 YEAR ���i���t�j �N���擾 SELECT YEAR(item) FROM table_name item��iYYYY-MM-DD�`���j����N(YYYY)�݂̂��擾 MONTH ���i���t�j �����擾 SELECT MONTH(item) FROM table_name item��iYYYY-MM-DD�`���j���猎(MM)�݂̂��擾 DAYOFMONTH ���i���t�j ���t���擾 SELECT DAYOFMONTH(item) FROM table_name item��iYYYY-MM-DD�`���j������t�iDD�j�݂̂��擾 HOUR ���i���t�j �����擾 SELECT HOUR(item) FROM table_name item��ihh:mm:ss�`���j���玞(hh)�݂̂��擾 MINUTE ���i���t�j �����擾 SELECT MINUTE(item) FROM table_name item��ihh:mm:ss�`���j���番(mm)�݂̂��擾 SECOND ���i���t�j �b���擾 SELECT SECOND(item) FROM table_name item��ihh:mm:ss�`���j����b(ss)�݂̂��擾 DAYOFWEEK ���i���t�j �j�����擾 SELECT DAYOFWEEK(item) FROM table_name item��iYYYY-MM-DD�`���j����j���݂̂��v�Z���Ď擾 DAYNAME ���i���t�j �j�������擾 SELECT DAYNAME(item) FROM table_name item��iYYYY-MM-DD�`���j����j�������v�Z���Ď擾 MONTHNAME ���i���t�j �������擾 SELECT MONTHNAME(item) FROM table_name item��iYYYY-MM-DD�j���猎���݂̂��擾 DAYOFYEAR ���i���t�j �N�ԒʎZ�����擾 SELECT DAYOFYEAR(item) FROM table_name YYYY/01/01����item��iYYYY-MM-DD�`���j�܂ł̌o�ߓ������v�Z���Ď擾 WEEK ���i���t�j �N�ԒʎZ�T���擾 SELECT WEEK(item) FROM table_name YYYY/01/01����item��iYYYY-MM-DD�`���j�܂ł̌o�ߏT�����v�Z���Ď擾 NULLIF ���i�ϊ��j NULL�ϊ� SELECT NULLIF(item1,item2) FROM table_name item1���item2�������ꍇ�ANULL�ɕϊ� ABS ���i�ϊ��j ��Βl SELECT ABS(item) FROM table_name item��̐�Βl���v�Z SIN ���i�ϊ��j �T�C�� SELECT SIN(item) FROM table_name item��̃T�C�����v�Z�i�����̒P�ʂ̓��W�A���j COS ���i�ϊ��j �R�T�C�� SELECT COS(item) FROM table_name item��̃R�T�C�����v�Z�i�����̒P�ʂ̓��W�A���j TAN ���i�ϊ��j �^���W�F���g SELECT TAN(item) FROM table_name item��̃^���W�F���g���v�Z�i�����̒P�ʂ̓��W�A���j COT ���i�ϊ��j �R�^���W�F���g SELECT COT(item) FROM table_name item��̃R�^���W�F���g���v�Z�i�P�ʂ̓��W�A���j ASIN ���i�ϊ��j �t�T�C�� SELECT ASIN(item) FROM table_name item��̋t�T�C�����v�Z�i�P�ʂ̓��W�A���j ACOS ���i�ϊ��j �t�R�T�C�� SELECT ACOS(item) FROM table_name item��̋t�R�T�C�����v�Z�i�P�ʂ̓��W�A���j ATAN ���i�ϊ��j �t�^���W�F���g SELECT ATAN(item) FROM table_name item��̋t�^���W�F���g���v�Z�i�P�ʂ̓��W�A���j ATAN2 ���i�ϊ��j �t�^���W�F���g SELECT ATAN2(item1,item2) FROM table_name item1���item2��ɂ��t�^���W�F���g���v�Z�i�P�ʂ̓��W�A���j CEILING ���i�ϊ��j �ŏ������l SELECT CEILING(item) FROM table_name item��ɂ����āA�ł������������l���v�Z�i�����_�ȉ���̂āj FLOOR ���i�ϊ��j �ő吮���l SELECT FLOOR(item) FROM table_name item��ɂ����āA�ł��傫�������l���v�Z�i�����_�ȉ���̂āj DEGREES ���i�ϊ��j ���W�A����x�ɕϊ� SELECT DEGREES(item) FROM table_name item��i���W�A���j��x�ɕϊ� RADIANS ���i�ϊ��j �x�����W�A���ɕϊ� SELECT RADIANS(item) FROM table_name item��i�x�j�����W�A���ɕϊ� EXP ���i�ϊ��j �w���l SELECT EXP(item) FROM table_name item��̎w���l���v�Z GREATEST ���i�ϊ��j �ő�l SELECT GREATEST(item1,item2,item3) FROM table_name ��item1,item2,item3�̒��ōł��傫���l���v�Z�i�����̌��͉ϒ��j LEAST ���i�ϊ��j �ŏ��l SELECT LEAST(item1,item2,item3) FROM table_name ��item1,item2,item3�̒��ōł��������l���v�Z�i�����̌��͉ϒ��j MOD ���i�ϊ��j �]����v�Z SELECT MOD(item1,item2) FROM table_name item1��item2��̗]����v�Z POW ���i�ϊ��j �ׂ��� SELECT POW(item1,item2) FROM table_name item1���item2�����v�Z SQRT ���i�ϊ��j ������ SELECT SQRT(item) FROM table_name item1��̕��������v�Z ROUND ���i�ϊ��j �l�̌ܓ� SELECT ROUND(item1,2) FROM table_name item1��̒l�������_�ȉ�2�����c��悤�Ɏl�̌ܓ� SIGN ���i�ϊ��j ���� SELECT SIGN(item) FROM table_name item��̕������擾�i���F0/���F-1/0�F0�j RAND ���i�ϊ��j ���� SELECT RAND() ����(�����_���Ȑ��l)���擾 PI ���i�ϊ��j �~���� SELECT PI() �~�������擾