基于SQL中的数据查询语句汇总
以下是对SQL中的数据查询语句进行了汇总介绍,需要的朋友可以过来参考下 where条件表达式 --统计函数 复制代码 代码如下: Select count(1) from student; --like模糊查询 --统计班上姓张的人数 复制代码 代码如下: select count(*) from student where realN
以下是对SQL中的数据查询语句进行了汇总介绍,需要的朋友可以过来参考下
where条件表达式
--统计函数
复制代码 代码如下:
Select count(1) from student;
--like模糊查询
--统计班上姓张的人数
复制代码 代码如下:
select count(*) from student where realName like '张%';
--统计班上张姓两个字的人数
复制代码 代码如下:
select count(*) from student where realName like '张_';
--统计班上杭州籍的学生人数
复制代码 代码如下:
select count(*) from student where home like '%杭州%';
--查询班上每位学生的年龄
复制代码 代码如下:
select realName,year(now())-year(birthday) as age from student;
--查询90年出生的学生
复制代码 代码如下:
select realName from student where year(birthday)>='1990';
--查询1987-1990年出生的学生
复制代码 代码如下:
select realName from student where year(birthday)='1987';
select * from student where year(birthday) between '1987' and '1990';
--查询班上男女生人数
复制代码 代码如下:
select sex,count(*) from student group by sex;
--in子句查询班上B或O型血的学生
复制代码 代码如下:
select realName,blood from student where blood in('B','O');
子查询
子查询也可称之为嵌套查询,有些时候,一次查询不能解决问题,需要多次查询。
按子查询返回的记录行数区分,可分为单行子查询和多行子查询;
复制代码 代码如下:
select * from emp where sal>( select sal from emp where ename='ALLEN‘ or ename =‘KING')
上例是找出比allen工资高的所有员工
A.子查询一般先于主语句的运行
B.必须有( ),表示一个整体
C.习惯上把子查询放在条件的右边
多行子查询:some,any,all
连接语句(应用于多表查询)
包括:内联,,外联(左外连和右外联)
内联(inner join):把两张表相匹配的行查询出来。
--查询每个学生的各科成绩,显示“姓名”“课程名”“分数”三列
复制代码 代码如下:
select a.realname,c.courseName,b.score from stu_student as a inner join stu_score as b on a.sid=b.sid inner join stu_course c on b.cid=c.cid
还有一种方法,不采用inner join:
复制代码 代码如下:
select a.realname,c.courseName,b.score from student a,score b,course c where a.sid=b.sid and c.cid=b.cid
外联分左外联和右外联:
Left outer join:查询两边表的匹配记录,且将左表的不匹配记录也查询出来。
Right outer join:等上,将右表不匹配记录也查询出来。
复制代码 代码如下:
select a.realname,b.score from stu_student as a left outer join stu_score as b on a.sid=b.sid

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

CakePHP is a popular PHP framework that provides convenient ORM (Object Relational Mapping) functionality that makes querying and updating the database very easy. This article will introduce how to query and update data in CakePHP. We'll start with simple queries and updates and work our way up to see how to use conditions and associated models to query and update data more complexly. Basic Query First, let's see how to make the simplest query. Let's say we have a data table called "Users" and we want

Some people want to update win11, but they don’t know if there are many bugs in win11 and whether the update will cause problems. In fact, there are bugs in win11 now, but they have little impact on use. Are there many bugs in win11? Answer: There are still many bugs in win11. However, these bugs have little impact on daily use. If the user has high requirements for daily use, it is recommended to use it later. Summary of win11 bugs 1. Resource Manager 1. Sometimes memory overflow occurs, resulting in high memory usage of the Resource Manager. 2. This situation will cause the memory to occupy more than 70%, causing the computer to freeze or even crash. 2. Conflict and crash 1. Some applications are not compatible enough, causing conflicts with each other. 2. Although there are relatively few conflict procedures,

As a powerful programming language, PHP provides a wealth of string processing functions. With the development of the Internet, string processing has increasingly become an indispensable part of Web development. In PHP, the string replacement function is used to search and replace specific text in a string. The following is a summary of commonly used string replacement functions in PHP. str_replace The str_replace function is one of the most commonly used string replacement functions in PHP. It can replace a certain substring in a string. The syntax of this function is as follows

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

MySQL and Python: How to implement data query function In recent years, the rapid growth of data has made data query and analysis an important task in various fields. As a widely used relational database management system, MySQL, combined with Python, a powerful programming language, can provide fast and flexible data query functions. This article will introduce how to use MySQL and Python to implement data query functions and provide code examples. First, we need to install and configure MySQL and Python

Comparison of data query and analysis capabilities between MySQL and TiDB As the amount of data continues to grow and application scenarios become more complex, data query and analysis capabilities have become one of the core competitiveness of various data storage systems. As one of the representatives of relational databases, MySQL has been widely used in stand-alone environments. However, as the business scale continues to expand, MySQL has certain limitations in processing large-scale data and high-concurrency queries. TiDB is an emerging distributed database system that solves these problems.

With the development of web applications, PHP language has been widely used in web development. In the PHP8.0 version, a new language feature was introduced - the multi-catch statement. What is a multi-catch statement? In previous PHP versions, developers needed to write multiple catch statements to handle multiple exception types. For example, the following code block shows the handling of two different exceptions: try{//Somecodethatmay

The problem of anomaly detection based on time series requires specific code examples. Time series data is data recorded in a certain order over time, such as stock prices, temperature changes, traffic flow, etc. In practical applications, anomaly detection of time series data is of great significance. An outlier can be an extreme value that is inconsistent with normal data, noise, erroneous data, or an unexpected event in a specific situation. Anomaly detection can help us discover these anomalies and take appropriate measures. For time series anomaly detection problems, commonly used
