Home > Database > Mysql Tutorial > body text

mysql check

黄舟
Release: 2017-01-16 13:14:20
Original
1165 people have browsed it

Get how many rows there are in the table
Tips:

select count(*) from table_name;
Copy after login


Get the columns with cat_id=4 and cat_id=11
Use or select * from goods where cat_id=4 or cat_id=11 ;
Do not use or select * from goods where cat_id in(4,11);

Get the price>=100 and<=500

select * from goods where shop_price >= 100 and shop_price <= 500;
select * from goods where shop_price between 100 and 500;
Copy after login

Get the price< ;=100 and>=500

select * from goods where shop_price <=100 and shop_price >= 500;
select * from goods where shop_price not between 100 and 500;
Copy after login

in is the set of scatter points, between and is the interval

cat_id is not a column of 3 or 11

select * from goods where cat_id!=3 and cat_id!=11;
select * from goods where cat_id not in(3,11);
Copy after login

Calculate the discount value than the market price

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods ;
Copy after login

Find the local price that is more than 200 cheaper than the market price

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods where (market_price - shop_price) > 200;
Copy after login



(The chajia column is generated after where has been used)

Doubtful points note: where works on the data in the real table, and having can filter the where results

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods where chajia > 200;(错误的)
Copy after login

The same effect

select goods_id,(market_price-shop_price) as chajia ,goods_name from goods having chajia>200;
Copy after login

Change [20,29] in the num column in the main table to 20 [30,39] to 30

update mian set num = floor(num/10)*10 where num between 20 and 39;
Copy after login

likeFuzzy query

Intercept the content after Nokia

select goods_id ,goods_name,substring(goods_name,4) from goods where goods_name like &#39;诺基亚%&#39;;
Copy after login

Find the content starting with Nokia and replace it with htc (no change to the real table content)

select goods_id ,goods_name,concat(&#39;htc&#39;,substring(goods_name,4)) from goods where goods_name like &#39;诺基亚%&#39;;
Copy after login

Replace Nokia with htc (change the real table content)

update goods 
set goods_name = concat(&#39;htc&#39;,substring(goods_name,4))
where goods_name like &#39;诺基亚%&#39; and cat_id=4;
Copy after login

The above is the content of mysql query. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template