国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Java JavaBase What are the mysql query statements in java

What are the mysql query statements in java

Nov 02, 2020 pm 03:36 PM
java

mysql query statements in java: 1. Simple query; 2. Simple query; 3. Sorting query; 4. Group query, the code is [group by grouped field.[Having condition]]; 5. For paging query, the code is [select * from table name limit x;].

What are the mysql query statements in java

mysql query statement in java:

1. Simple query

–Query all fields:

select * from table name;

- - Query specified fields:

select field 1, field 2... from table name;

- - Table alias: If there are special symbols or spaces in the alias, it needs to be enclosed in quotation marks

select * from table name [as] Table alias

- - Column Alias: as can be omitted.

select field 1 [as] alias, field 2 [as] alias from table name;

- - Remove duplicate values: If there are multiple fields, they must be Repeat.

select distinct field from table name;

- - Operation query:

select (math english) total score from table name;

2. Conditional query:

Comparison operators: > , < , = , >= , <= , <>(!=)

Logical operators:

between…and… : Values ??displayed in a certain interval (including head and tail)

in (multiple conditions) : or (or) relationship

like: Fuzzy query

% represents zero or more arbitrary characters.

_ represents one character.

is null: Determine whether it is empty.

3. Sorting query: Write at the end of the sql statement.

select * from table name order by sorting field ASC (ascending order - default)/DESC (descending order)

If there are multiple fields to be sorted, sort them by the first one first, and then sort by the following ones

4. Aggregation function: after select, before from.

sum (sum): The specified column is not a numeric type, and the calculation result is 0;

count (statistical number): does not include null; generally use *;

max (maximum value ): If it is a string type, use string sorting;

min(minimum value) :

avg(average): The specified column is not a numeric type, and the calculation result is 0;

5. Group query

group by 被分組的字段.[Having 條件]
  • where: Filter before group query.

  • having: Group query Post-filtering.

Note; Grouped fields are generally written after select as query conditions for easy viewing

6. Paging query (understand)

Use keyword limit

Format one: only the first x data

select * from 表名 limit x;

Format two: paging query

 select * from 表名 limit m,n;
  • m: The starting number of rows of data per page, changing

  • n: The number displayed on each page, fixed

Note:

The index of the row in the database starts from 0

The index of the column starts from 1

Single table case:

-- 創(chuàng)建數據庫
create database day03; 
-- 員工表
USE day03; 
CREATE TABLE emp(
     -- 員工編號
     empno   INT,
     -- 員工姓名
     ename   VARCHAR(50),
     -- 工作
     job  VARCHAR(50),
     -- 管理者
     mgr   INT,
     -- 雇用時間 
     hiredate   DATE,
     -- 工資
     sal  DECIMAL(7,2),
     -- 獎金
     comm  DECIMAL(7,2),
     -- 部門
     deptno  INT
) ;
-- 部門表
CREATE TABLE dept(
   -- 部門
   deptno  INT,
   -- 部門名稱
   dname  VARCHAR(14),
   -- 部門位置
   loc   VARCHAR(13)
   );
-- 向員工表中添加數據.
INSERT INTO emp VALUES(7369,&#39;SMITH&#39;,&#39;CLERK&#39;,7902,&#39;1980-12-17&#39;,800,NULL,20);
INSERT INTO emp VALUES(7499,&#39;ALLEN&#39;,&#39;SALESMAN&#39;,7698,&#39;1981-02-20&#39;,1600,300,30);
INSERT INTO emp VALUES(7521,&#39;WARD&#39;,&#39;SALESMAN&#39;,7698,&#39;1981-02-22&#39;,1250,500,30);
INSERT INTO emp VALUES(7566,&#39;JONES&#39;,&#39;MANAGER&#39;,7839,&#39;1981-04-02&#39;,2975,NULL,20);
INSERT INTO emp VALUES(7654,&#39;MARTIN&#39;,&#39;SALESMAN&#39;,7698,&#39;1981-09-28&#39;,1250,1400,30);
INSERT INTO emp VALUES(7698,&#39;BLAKE&#39;,&#39;MANAGER&#39;,7839,&#39;1981-05-01&#39;,2850,NULL,30);
INSERT INTO emp VALUES(7782,&#39;CLARK&#39;,&#39;MANAGER&#39;,7839,&#39;1981-06-09&#39;,2450,NULL,10);
INSERT INTO emp VALUES(7788,&#39;SCOTT&#39;,&#39;ANALYST&#39;,7566,&#39;1987-04-19&#39;,3000,NULL,20);
INSERT INTO emp VALUES(7839,&#39;KING&#39;,&#39;PRESIDENT&#39;,NULL,&#39;1981-11-17&#39;,5000,NULL,10);
INSERT INTO emp VALUES(7844,&#39;TURNER&#39;,&#39;SALESMAN&#39;,7698,&#39;1981-09-08&#39;,1500,0,30);
INSERT INTO emp VALUES(7876,&#39;ADAMS&#39;,&#39;CLERK&#39;,7788,&#39;1987-05-23&#39;,1100,NULL,20);
INSERT INTO emp VALUES(7900,&#39;JAMES&#39;,&#39;CLERK&#39;,7698,&#39;1981-12-03&#39;,950,NULL,30);
INSERT INTO emp VALUES(7902,&#39;FORD&#39;,&#39;ANALYST&#39;,7566,&#39;1981-12-03&#39;,3000,NULL,20);
INSERT INTO emp VALUES(7934,&#39;MILLER&#39;,&#39;CLERK&#39;,7782,&#39;1982-01-23&#39;,1300,NULL,10);
-- 向部門表添加數據 , 采用批量插入數據, 用 , 號隔開 .
INSERT INTO dept VALUES(10, &#39;ACCOUNTING&#39;, &#39;NEW YORK&#39;)
,(20, &#39;RESEARCH&#39;, &#39;DALLAS&#39;),(30, &#39;SALES&#39;, &#39;CHICAGO&#39;),
(40, &#39;OPERATIONS&#39;, &#39;BOSTON&#39;);
-- 1.  查詢工資大于1200的員工姓名和工資
SELECT ename 員工姓名 , sal 工資 FROM emp  WHERE sal > 1200;
-- 2.   查詢員工號為7698的員工的姓名和部門號
SELECT ename 員工姓名 , deptno 部門號 FROM emp WHERE empno = 7698;
-- 3.   選擇工資不在500到1200的員工的姓名和工資
SELECT ename 員工姓名 ,sal 工資 FROM emp WHERE sal<=1200 && sal >= 500;
-- 4.   選擇雇用時間在1981-02-01到1987-05-01之間的員工姓名,job_id和雇用時間
SELECT ename 員工姓名,empno , hiredate FROM emp WHERE hiredate BETWEEN &#39;1981-02-01&#39; AND &#39;1987-05-01&#39;;
-- 5.   選擇在20或30號部門工作的員工姓名和部門號
SELECT ename 員工姓名,deptno 部門號 FROM emp WHERE deptno IN(20 , 30 );
-- 6.   選擇在1981年雇用的員工的姓名和雇用時間
SELECT ename 員工姓名,hiredate 雇傭時間 FROM emp WHERE hiredate LIKE(&#39;1981-__-__&#39;);
-- 7.   選擇公司中沒有管理者的員工姓名及job_id
SELECT ename 員工姓名,empno FROM emp WHERE mgr IS NULL;
-- 8.   選擇公司中有獎金的員工姓名,工資和獎金級別
SELECT ename 員工姓名,sal 工資,comm 獎金 FROM emp WHERE comm IS NOT NULL OR;
-- 9.   選擇員工姓名的第三個字母是a的員工姓名
SELECT ename 員工姓名 FROM emp WHERE ename LIKE &#39;__A%&#39;;
-- 10.  選擇姓名中有字母a和e的員工姓名
SELECT ename 員工姓名 FROM emp WHERE ename LIKE &#39;%A%&#39; OR &#39;%E%&#39;
-- 11.  查詢員工號,姓名,工資,以及工資提高百分之20%后的結果(new salary)
SELECT empno 員工號, ename 姓名,sal+(sal*0.2) 工資 FROM emp;
-- 12.  將員工的姓名按首字母排序
SELECT ename FROM emp ORDER BY ename ASC; -- 升序
SELECT ename FROM emp ORDER BY ename DESC; -- 降序
-- 13.  查詢公司員工工資的最大值,最小值,平均值,總和
SELECT MAX(sal) 最大值,MIN(sal) 最小值 , AVG(sal) 平均值, SUM(sal) 總和 FROM emp;   
-- 14.  查詢各deptno的員工工資的最大值,最小值,平均值,總和
SELECT deptno 部門,MAX(sal) 最大值,MIN(sal) 最小值 , AVG(sal) 平均值, SUM(sal) 總和 FROM emp GROUP BY deptno;   
-- 15.  選擇具有各個deptno的員工人數
SELECT deptno , COUNT(empno) FROM emp GROUP BY deptno;

Related free learning recommendations: java basic tutorial, mysql video tutorial

The above is the detailed content of What are the mysql query statements in java. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to handle transactions in Java with JDBC? How to handle transactions in Java with JDBC? Aug 02, 2025 pm 12:29 PM

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

Understanding the Java Virtual Machine (JVM) Internals Understanding the Java Virtual Machine (JVM) Internals Aug 01, 2025 am 06:31 AM

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

How to work with Calendar in Java? How to work with Calendar in Java? Aug 02, 2025 am 02:38 AM

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Aug 04, 2025 pm 12:48 PM

Pre-formanceTartuptimeMoryusage, Quarkusandmicronautleadduetocompile-Timeprocessingandgraalvsupport, Withquarkusoftenperforminglightbetterine ServerLess scenarios.2.Thyvelopecosyste,

Understanding Network Ports and Firewalls Understanding Network Ports and Firewalls Aug 01, 2025 am 06:40 AM

Networkportsandfirewallsworktogethertoenablecommunicationwhileensuringsecurity.1.Networkportsarevirtualendpointsnumbered0–65535,withwell-knownportslike80(HTTP),443(HTTPS),22(SSH),and25(SMTP)identifyingspecificservices.2.PortsoperateoverTCP(reliable,c

How does garbage collection work in Java? How does garbage collection work in Java? Aug 02, 2025 pm 01:55 PM

Java's garbage collection (GC) is a mechanism that automatically manages memory, which reduces the risk of memory leakage by reclaiming unreachable objects. 1.GC judges the accessibility of the object from the root object (such as stack variables, active threads, static fields, etc.), and unreachable objects are marked as garbage. 2. Based on the mark-clearing algorithm, mark all reachable objects and clear unmarked objects. 3. Adopt a generational collection strategy: the new generation (Eden, S0, S1) frequently executes MinorGC; the elderly performs less but takes longer to perform MajorGC; Metaspace stores class metadata. 4. JVM provides a variety of GC devices: SerialGC is suitable for small applications; ParallelGC improves throughput; CMS reduces

Comparing Java Build Tools: Maven vs. Gradle Comparing Java Build Tools: Maven vs. Gradle Aug 03, 2025 pm 01:36 PM

Gradleisthebetterchoiceformostnewprojectsduetoitssuperiorflexibility,performance,andmoderntoolingsupport.1.Gradle’sGroovy/KotlinDSLismoreconciseandexpressivethanMaven’sverboseXML.2.GradleoutperformsMaveninbuildspeedwithincrementalcompilation,buildcac

go by example defer statement explained go by example defer statement explained Aug 02, 2025 am 06:26 AM

defer is used to perform specified operations before the function returns, such as cleaning resources; parameters are evaluated immediately when defer, and the functions are executed in the order of last-in-first-out (LIFO); 1. Multiple defers are executed in reverse order of declarations; 2. Commonly used for secure cleaning such as file closing; 3. The named return value can be modified; 4. It will be executed even if panic occurs, suitable for recovery; 5. Avoid abuse of defer in loops to prevent resource leakage; correct use can improve code security and readability.

See all articles