SQL statements used to obtain the maximum and minimum values of max () and min ()

Source: Internet
Author: User

1) create a database Test. mdb
2) import the data tables of info. mdb and info1.mdb, which are info and info1 respectively. The table data is as follows:
  

The code is as follows: Copy code
Info
-----
Product Name
1234
2345
  
Info1
---------
Product Name vendor price
1234 vendors 1 10
1234 Manufacturers 2 20
1234 manufacturers 3 30
2345 manufacturers 1 40
2345 Manufacturers 2 50
2345 manufacturers 3 60
3456 manufacturers 1 70
3456 Manufacturers 2 80
3456 manufacturers 3 90

   
3) Create a new query and open the SQL View (View> SQL view)
  
4) paste the following content and run

The code is as follows: Copy code
  
SELECT info1. name, Max (info1. price) AS price maximum, Min (info1. price) AS price minimum
FROM info1
Group by info1.
HAVING info1. name in (SELECT info. Name FROM info );


   
5) the running result is as follows:
  

The code is as follows: Copy code
Query 1: select query
------------
Product Name Price-maximum price-minimum
1234 30 10
2345 60 40


Tutorial function supplement

MAX () function
The MAX function returns the maximum value in a column. NULL values are not included in calculation.

SQL MAX () syntax
Select max (column_name) FROM table_name note: MIN and MAX can also be used in text columns to obtain the highest or lowest values in alphabetical order.

 

MIN () function
The MIN function returns the minimum value in a column. NULL values are not included in calculation.

SQL MIN () syntax
Select min (column_name) FROM table_name note: MIN and MAX can also be used in text columns to obtain the highest or lowest values in alphabetical order.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.