MySQL Common query

Source: Internet
Author: User

This article is the superior operation of the related chapters of the experimental building .

A) Create a database test, switch to the database, create a table in the database test, and insert the data,

1) Create and switch

2) Create a table and insert data

Show all the data in the table:

II) query statements

1) Find the maximum value of the column

Use the max () function to article the maximum value of the item number.

2) Query the row for the maximum value of a column

Displays the row for the Price column's maximum value:

Another way is to sort all the prices in descending order, and then use the MySQL-specific limit words to display one line (specify the first line to show the highest price):

Note: If the price of a number of items is 19.95 (that is, more than one of the most expensive items), then the result of limit display will only be one of them.

3) display the maximum value of the column by group

Use the following code to find out the highest price for each item :

4) Using User variables

Find the item with the highest or lowest price by using user variables

5) Use a foreign key or learn more.

6) Calculate the monthly traffic

Use the Bit_count function to calculate the number of days a user accesses a webpage per month. First, create a table T1 that represents the year-month day when a user visits a webpage:

Use the following statement to query the number of visits per month:

Note: Bit_count () is used to calculate the number of binary numbers containing 1, such as: SELECT Bit_count (10), because 10 becomes a binary number of 1010, the result is 2.

Bit_or () is used to perform or operate on two binary numbers.

After all or operation, the stats are set to 1 bit number to know how many days of the month are accessed.

Small white Study Data blog on this has to explain, interested can see.

MySQL Common query

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.