Study Diary on March 29, 2021

3.29 Review of learning

Today, I mainly learned the main query method of the single table of the MySQL database.

One, MySQL database query

  1. Common codes for single table query
    (1) Display table structure: DESC d_book;
    (2) Display all data of the table: SELECT * FROM d_book;
    (3) Display some field data in the table: SELECT id, author FROM d_book;
    (4) Display Some fields in the table are equal to a single fixed value data:
    (5) SELECT * FROM d_book WHERE publishing='Beijing October Literature and Art Publishing House';
    (6) SELECT * FROM d_product WHERE dang_price <=22;
    (7) SELECT * FROM d_book WHERE total_page <400;
    (8) Some fields in the display table are equal to multiple fixed-value data: SELECT * FROM d_book WHERE author IN('Mo Yan','Luyao','Nanpai Sanshu','Feyuehe');
    (9) Data in a certain value range (including values): SELECT * FROM d_product WHERE dang_price BETWEEN 50 AND 100;
    (10) Fuzzy query (percent sign indicates unlimited bytes of data, underscore indicates one byte):
    SELECT * FROM d_book WHERE author LIKE'张%';
    SELECT * FROM d_book WHERE author LIKE'__';
    (11) Deduplication: SELECT DISTINCT publishing FROM d_book;
    (12) Sort—ascending order (default ascending order if not set): SELECT * FROM d_product ORDER BY dang_price ASC;
    (13) Sort—descending order: SELECT * FROM d_product ORDER BY fixed_price DESC;
    (14) Group by field: SELECT publishing, GROUP_CONCAT (author) FROM d_book GROUP BY publishing;
    (15) Summarize the grouped data into the bracketed fields: SELECT publishing, GROUP_CONCAT(author) FROM d_book GROUP BY publishing;
    (16) Limit number-display the first few rows of data (note: Here by default the first row is 0, the second row is 1...that is, limit5 means rows 0-4): SELECT * FROM d_category WHERE turn=1 LIMIT 5;
    (17) Limit number 1 and number 2—— Starting from the first few rows, display 2 rows of data (note: the default here is 0 for the first row, and 1 for the second row...that is, limit2,3 means starting from the second row and displaying the next 3 rows of data): * the FROM d_category the WHERE Turn the SELECT = 2,4. 1 the LIMIT;
    (18 is) cOUNT ( ) - count (Note: in brackets is the time when the count result includes a null row, in brackets particular field, the counting result does not contain null lines) : SELECT COUNT( ) FROM d_book;
    Sum, maximum, minimum, average: SELECT SUM(dang_price),MAX(dang_price),MIN(dang_price),AVG(dang_price) FROM d_product;
    (19) having-second screening of the results: SELECT class, COUNT(class),AVG(height) FROM school GROUP BY class HAVING AVG(height)<160;
    (20)'' —— put a space after the field with quotation marks, Chinese in the quotation marks, the displayable field name is Chinese: SELECT empno ' Employee ID' ,ename'employee name' ,12

    sal'annual salary' FROM emp; (21) ifnull (field, 0)-when summing the field, if the field contains a null value, then null is calculated as 0:
    SELECT empno'Employee Number', ename'Employee Name', 12*(sal+IFNULL(comm,0))'Annual Income' FROM emp;

Guess you like

Origin blog.csdn.net/weixin_56039103/article/details/115307486