SQL Server Learning record (04) - MIN () function

SQL Server Learning record (04) - MIN function


Copyright Notice

  • This article original author: no cross breeze
  • Blog address: https: //blog.csdn.net/WXKKang

  First, create a set of test data for learning MIN () function, as follows:

CREATE TABLE student(
	s_id varchar(50) NOT NULL PRIMARY KEY,
	s_name varchar(50),
	s_gender varchar(50),
	s_age int
)

INSERT INTO student(s_id,s_name,s_gender,s_age) VALUES ('S101','Tom','male',18);
INSERT INTO student(s_id,s_name,s_gender,s_age) VALUES ('S102','Lucy','female',18);
INSERT INTO student(s_id,s_name,s_gender,s_age) VALUES ('S103','Jack','male',19);
INSERT INTO student(s_id,s_name,s_gender,s_age) VALUES ('S104','Bruce','male',16);
INSERT INTO student(s_id,s_name,s_gender,s_age) VALUES ('S105','Jayce','male',23);

A, MIN () function

  MIN () function returns the minimum value of the selected column

1, the basic grammar

  The basic syntax is as follows:

SELECT MIN(column_name)
FROM table_name
WHERE condition;

2, Example

  Here we find a student by way of example above table how old is the youngest, as follows:

SELECT MIN(s_age) as 'max_age' FROM student;

  Execution results are as follows:
Here Insert Picture Description
  You can also find basic information about the youngest students through this function code is as follows:

SELECT * FROM student WHERE s_age=(SELECT MIN(s_age) FROM student)

  Execution results are as follows:
Here Insert Picture Description

Published 80 original articles · won praise 36 · views 3317

Guess you like

Origin blog.csdn.net/WXKKang/article/details/104039575