gogoWebsite

MySQL product query, mysql basic query

Updated to 1 day ago

-- Simple query

-- Query all products

SELECT * FROM product;

-- Query the product name and product price.

SELECT pname,price FROM product;

-- Query the price and remove duplicate values.

SELECT DISTINCT price FROM product;

-- The query result is an expression (operation query): displays the price of all products +10 yuan.

SELECT pname,price+10 FROM product;

-- Alias ​​query. The keyword used is as (as can be omitted). Column alias

SELECT pname,price+10 AS 'price' FROM product;

-- Conditional query

SELECT * from product;

-- Query the product name and product price.

select pname,price from product;

-- Query the price and remove duplicate values.

select DISTINCT price from product;

-- The query result is an expression (operation query): displays the price of all products +10 yuan.

select pname,price+10 from product;

-- Alias ​​query. The keyword used is as (as can be omitted). Column alias

select pname,price+10 as 'price' from product;

select pname,price+10 'price' from product;

-- Alias ​​query. The keyword used is as (as can be omitted). Table alias

select * from product as p;

select * from product p;

#Query all information about products with product name "Playboy":

SELECT * FROM product WHERE pname="playboy";

#Query price is 800 items

SELECT * FROM product WHERE price=800;

#Query all items whose prices are not 800

SELECT * FROM product WHERE price<>800;

#Query all product information for product prices greater than 60 yuan

SELECT * FROM product WHERE price>60;

#Query all products between 200 and 1000

SELECT * FROM product WHERE price>=200 AND price =<1000;

SELECT * FROM product WHERE price BETWEEN 200 and 1000;

#Query all products whose product price is 200 or 800

SELECT * FROM product WHERE price=200 OR price=800;

SELECT * FROM product WHERE price in (200,800);

#Query all products with the word 'Ba'

SELECT * FROM product WHERE pname LIKE '%Bor%';

#Query all products whose product names start with 'Fragrance'

SELECT * FROM product where pname = 'Chanel';

# Sort query

select * from product ORDER BY price desc;

# Aggregation Query

SELECT COUNT(*) FROM product;

# Check the total number of items with prices greater than 200

SELECT COUNT(*) FROM product where price>200;

# Group query

SELECT category_id,count(*) from product GROUP BY category_id;

# Conditional restriction query

SELECT * from product limit 10,5;

Tags: basic, product,--, price, query, pname, mysql, SELECT

Source: /weixin_42454617/article/details/112472418