当前位置:网站首页>How to use the select statement of MySQL
How to use the select statement of MySQL
2022-06-29 04:22:00 【Yisu cloud】
MySQL Of select How to use statements
This article “MySQL Of select How to use statements ” Most people don't quite understand the knowledge points of the article , So I made up the following summary for you , Detailed content , The steps are clear , It has certain reference value , I hope you can gain something after reading this article , Let's take a look at this article “MySQL Of select How to use statements ” Article bar .

select Statement can To separate... With carriage return
$sql="select * from article where id=1" and $sql="select * from article where id=1" Can get the right results , But sometimes writing separately may More clearly , Especially when sql When the statement is long .
Bulk query data
It can be used in To achieve $sql="select * from article where id ;in(1,3,5)"
Use concat Connect the results of the query
$sql="select concat(id,"-",con) as res from article where id=1" return "1-article content"
Use locate
usage : select locate("hello","hello baby"); return 1
There is no return 0Use group by
I haven't figured it out before group by and order by, It's actually quite simple ,group by Is to tie the same knot Make the fruit into a group exam:$sql="select city ,count(*) from customer group by city"; The meaning of this sentence is Thinking is from customer The table lists all cities that do not repeat , And quantity ( It's kind of similar distinct) group by Often with AVG(),MIN(),MAX(),SUM(),COUNT() Use it together
Use having
having Allow conditional aggregation of data into groups $sql="select city,count(*),min(birth_day) from customer group by city having c ount(*)>10"; This sentence is to press city Grouping , Then find out city The quantity of land is greater than 10 The city of City btw: Use group by + having It's a little slow Same as when having Clause must contain an expression that has occurred before
Combined clause
where、 group by、having、order by( If you want to use all four , Usually press this In one order )
Use distinct
distinct It is used to remove duplicate values $sql="select distinct city from customer order by id desc"; This sentence means from customer Look up in the table Ask for all non repetitive city
Use limit
If you want to display the information after a record Records $sql="select * from article limit 100,- 1";
Multi-table query
$sql="select user_name from user u,membe r m where u.id=m.id and m.reg_date> ;=2006-12-28 order by u.id desc"
Be careful : If user and member Both labels have user_name Field , There will be mysql error ( because mysql I didn't know you were there Which table do you want to query user_name), You must indicate which table it belongs to .
That's about “MySQL Of select How to use statements ” The content of this article , I believe we all have a certain understanding , I hope the content shared by Xiaobian will be helpful to you , If you want to know more about it , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- 【HackTheBox】dancing(SMB)
- 1019 digital black hole
- sql数据库存储过程写法
- Is the increased life insurance off the shelf? What additional life insurance products are available now?
- The people's Bank of China printed and distributed the notice on supporting cross-border RMB settlement of new foreign trade formats
- 自己动手搭建一个简单的网站
- If you choose the right school, you can enter Huawei as a junior college. I wish I had known
- 1016 part a+b
- Gocd is good, but talk about Jenkins
- 为什么说测试岗位是巨坑?8年测试人告诉你千万别上当
猜你喜欢

LabVIEW displays Unicode characters

Anaconda's own Spyder editor starts with an error

Remote connection of raspberry pie in VNC Viewer Mode

Blue Bridge Cup ruler method

为什么说测试岗位是巨坑?8年测试人告诉你千万别上当
![[new function] ambire wallet integrates Metis network](/img/29/8a8c0cd40c51cef1174ee59706d4c9.png)
[new function] ambire wallet integrates Metis network

ROS URDF model is parsed into KDL tree

The second meeting of the Second Council of Euler open source community was held, and Xinhua III, hyperfusion and Godson Zhongke became members of the Council

moudo网络库剖析

Libuv library overview and comparison of libevent, libev and libuv (Reprint)
随机推荐
【HackTheBox】dancing(SMB)
如何创建 robots.txt 文件?
Cloud native weekly | grafana 9 was officially released; The Chinese version of cloud native vocabulary is now online
人民银行印发《关于支持外贸新业态跨境人民币结算的通知》
Ling Jing thinks about her own way
热更新流程
JDBC man Han building code
Has my future been considered in the cloud native development route?
New listing of operation light 3.0 -- a sincere work of self subversion across the times
[WC2021] 斐波那契——数论、斐波那契数列
EEG signal processing - wavelet transform series
树莓派用VNC Viewer方式远程连接
云主机mysql在本地电脑连接不上
Ask a simple question about SQL
Technology: how to design zkvm circuit
直播预约|AWS Data Everywhere 系列活动
sink端 一般都是jdbc的insert update delete么?
moudo网络库剖析
SqlServer如何查询除去整列字段为null的结果
SEAttention 通道注意力机制