Database administration tool Navicat Premium Tutorial: Several important SELECT statement

Navicat Premium is a management tool can be connected to multiple databases, it allows you to connect to a single MySQL, Oracle and PostgreSQL databases simultaneously, so that different types of database management more convenient.

Data is the core of many large and small businesses. For example, Facebook profile information is stored for each user, including data on posts within their friends and database systems. (Abbreviation for Structured Query Language) SQL is a programming language that enables developers and database administrators to use the data.

For database work, you should be familiar with some common SQL commands. Does not include data definition language (DDL) or Data Manipulation Language (DML) statements, SQL SELECT statement command includes command data acquired from the tables and views. Today's article will introduce some of the most important queries, as well as some examples of the use of Navicat Premium as the database client.

Determine the column minimum / maximum value

The Sakila sample database contains many covers everything from actors and movie studios to video rental stores around the film industry as the theme of the table. We will be here today to build a query will run against it, so you may need to refer to the tutorial on MySQL data to generate reports in order to get instructions on downloading and installing Sakila database.

Sakila a center table in the database is a movie list. It contains details of our fictional video rental store owned by each film. It includes a movie title, release year and rental prices and other information:

24film_table(1).jpg

Suppose we want to know what price range - that is, the minimum and maximum rent is how much? We could easily find use MIN () and MAX () aggregate function. Aggregate functions perform a set of calculation result and return a single value. There are many aggregate functions, including AVG, COUNT, SUM, MIN, MAX and the like. This is a query to MIN () and MAX () is applied to the film table rental_rate field:

SELECT MIN(f.rental_rate) as lowest_price,
       MAX(f.rental_rate) as highest_price
FROM film f;

As expected, each function returns a value:

25lowest_highest_rental_price.jpg

Group results by categories

SQL is the most powerful is a clause GROUP BY. Row will have the same value in the packet to the summary row. Thus, GROUP BY statement commonly used with aggregate functions (COUNT, MAX, MIN, SUM, AVG), the result set to the grouped into one or more columns.

We can use the GROUP BY clause lists the minimum and maximum rent cost per movie ratings, such as "General", "PG", "PG-13" and so on. We need to do is add a rating field to the column list and additional GROUP BY clause to the end of our existing query:

SELECT f.rating,
       MIN(f.rental_rate) as lowest_price,
       MAX(f.rental_rate) as highest_price
FROM film f
GROUP BY f.rating;

Our results show that per-rated movies range in price from $ 0.99 to $ 4.99:

26lowest_highest_rental_price_grouped_by_rating.jpg

in conclusion

Today's blog describes some of the most important queries, as well as some examples of the use of Navicat Premium as the database client. Navicat and remove duplicate keywords get through recommendations from coding to help you quickly write code completion and customizable code snippets.


Guess you like

Origin blog.51cto.com/14467432/2438455