0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SOL 文の速攻雛形

Last updated at Posted at 2020-10-22

いつも忘れてしまうので、
雛形作成しました!

※苦手なORDER BY文も記載しています。


CREATE DATABASE test; --データベースを作る

USE test; --デフォルトで使用するデータベースを指定する

CREATE TABLE users (*** VARCHAR(100), *** INT); --カラムを作成

INSERT INTO users (***, ***) VALUES ('任意の値', 任意の値); --insert文

INSERT INTO users (***, ***) VALUES ('任意の値', 任意の値);

INSERT INTO users (***, ***) VALUES ('任意の値', 任意の値);

INSERT INTO users (***, ***) VALUES ('任意の値', 任意の値);

INSERT INTO users (***, ***) VALUES ('任意の値', 任意の値);

INSERT INTO users (***, ***) VALUES ('任意の値', 任意の値);


SELECT * FROM *** ORDER BY test; --ORDER BY 昇順文

SELECT * FROM *** ORDER BY test DESC;--ORDER BY 降順文

SELECT * FROM *** WHERE *** LIKE '%任意の値%' ORDER BY 任意の値; 
--条件を絞ったORDER BY文 (検索してから、昇順)

SELECT * FROM *** ORDER BY FIELD(***, 'test1', 'test2', 'test3'); 
--FIELD関数+ORDER BYを使用した文 任意の値に並び替えることが可能。

SELECT * FROM *** ORDER BY test_score >= 30 DESC;
--数字条件付きORDER BY文

SELECT * FROM users ORDER BY BINARY name;
--BINARY付けると 大文字と小文字を区別してソートする文

SELECT * FROM examples ORDER BY 2 ASC;
--ORDER BY文の後に列数を入れると任意列をソートすることが出来る文




0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?