查询表语句,以及嵌套

CREATE TABLE classes(
class_id INT PRIMARY KEY auto_increment,
class_name VARCHAR(20),
class_address VARCHAR(20)
class_mainTeacher VARCHAR(20)
)

CREATE TABLE student (
stu_id int PRIMARY KEY auto_increment,
stu_name VARCHAR(20) NOT NULL,
stu_age int NOT NULL,
stu_phone VARCHAR(20) UNIQUE,
stu_qq VARCHAR(20) UNIQUE,
stu_address VARCHAR(20) DEFAULT ‘ChengDuSchool‘,
class_id int,
CONSTRAINT FK_student_classId FOREIGN KEY(class_id) REFERENCES classes(class_id)

)

p.f_name,
p.f_dateOfBirth,
p.f_number,
p.f_place,
p.f_club
FROM
t_player as p
WHERE
-- p.f_club = "皇家马德里" AND p.f_place = "前锋"
-- p.f_place = "门将" AND (p.f_dateOfBirth < ‘1980-1-1‘ OR p.f_dateOfBirth > ‘1970-12-31‘)
-- p.f_club in("阿森纳","AC米兰")
p.f_name LIKE "__斯基"
order by
f_dateofBirth asc

UPDATE t_player SET f_club = NULL WHERE t_player.f_club in (‘未知‘,"无")

-- UPDATE t_player SET f_club = "未知" WHERE t_player.f_club = NULL
SELECT
p.f_name,
p.f_club,
p.f_dateOfBirth,
p.f_place
FROM
t_player as p
WHERE
-- p.f_club = ‘皇家马德里‘ AND p.f_place = ‘前锋‘ AND (p.f_dateOfBirth BETWEEN ‘1980-1-1‘ AND ‘1989-12-31‘);
p.f_place NOT IN(‘门将‘) AND (p.f_dateOfBirth BETWEEN ‘1990-1-1‘ AND ‘1999-12-31‘) AND p.f_name LIKE "%尔%"

SELECT COUNT(*), t_player.f_club FROM t_player GROUP BY f_club ORDER BY COUNT(*) DESC

SELECT COUNT(*), t_player.f_club,t_player.f_place FROM t_player GROUP BY f_club,f_place

SELECT fk_teamid,COUNT(*) from t_player WHERE f_place = ‘后卫‘ GROUP BY fk_teamid HAVING COUNT(*) > 8

-- SELECT contryName FROM bbc WHERE population >= 200000000
-- SELECT contryName,bbc.gdp/bbc.population FROM bbc WHERE population >= 200000000
-- SELECT bbc.contryName,ROUND(bbc.population/1000000) from bbc WHERE bbc.region = ‘south Asia‘
-- SELECT bbc.contryName,bbc.population FROM bbc WHERE bbc.contryName IN ("France","Germany","Italy")
-- SELECT bbc.contryName FROM bbc WHERE bbc.contryName LIKE "%United%"
-- SELECT DISTINCT bbc.region FROM bbc
-- SELECT bbc.contryName,bbc.population FROM bbc WHERE bbc.population >= 100000000 ORDER BY bbc.population DESC

-- SELECT SUM(bbc.population) as 世界人口总和 FROM bbc
-- SELECT DISTINCT bbc.contryArea FROM bbc
-- SELECT bbc.contryName,bbc.gdp FROM bbc WHERE bbc.gdp > (SELECT SUM(bbc.gdp) FROM bbc WHERE bbc.region = "Africa") ORDER BY bbc.gdp DESC
-- SELECT bbc.region,COUNT(*) as 国家总数 FROM bbc GROUP BY bbc.region ORDER BY COUNT(*) DESC
-- SELECT bbc.region,SUM(bbc.population) as 地区总人口,SUM(bbc.contryArea) AS 地区总面积 FROM bbc GROUP BY bbc.region ORDER BY SUM(bbc.population) DESC
-- SELECT bbc.region,COUNT(*) as 该地区人口大于1000万的国家总数 FROM bbc WHERE bbc.population >= 10000000 GROUP BY bbc.region ORDER BY COUNT(*) DESC
-- SELECT bbc.region,SUM(bbc.population) AS 人口总数大于一亿 FROM bbc GROUP BY bbc.region HAVING SUM(bbc.population) >= 100000000 ORDER BY SUM(bbc.population) DESC
-- SELECT SUM(bbc.population) as 欧洲人口总数,SUM(bbc.gdp) as 欧洲总gdp FROM bbc WHERE bbc.region = ‘Europe‘
SELECT bbc.region,SUM(bbc.population) as 总人口数,SUM(bbc.contryArea) as 总面积 FROM bbc GROUP BY region HAVING SUM(bbc.contryArea) >= 1000000 ORDER BY SUM(bbc.population) DESC

SELECT t_player.f_name,(SELECT t_team.f_teamCoach FROM t_team WHERE t_player.fk_teamid = t_team.pk_teamid) FROM t_player WHERE t_player.f_club = "尤文图斯"

SELECT t_player.f_name,(SELECT t_team.f_teamCoach FROM t_team WHERE t_team.pk_teamid = t_player.fk_teamid) as coach,(SELECT t_group.f_groupAddress FROM t_group WHERE t_group.pk_groupid = (SELECT pk_teamid FROM t_team WHERE t_player.fk_teamid = t_team.pk_teamid)) FROM t_player WHERE t_player.f_club = "尤文图斯"

时间: 2024-11-11 15:34:28

查询表语句,以及嵌套的相关文章

关于INSERT EXEC 语句不能嵌套的解决办法

一.问题  之前做项目的时候遇到过要在一个存储过程要操作另一个存储过程返回的结果集,想通过调用的存储过程保存到局部临时表进行操作.执行下面的sql,会提示: 消息 8164,级别 16,状态 1,过程 zryCreatePlantPlanningReport,第 27 行 INSERT EXEC 语句不能嵌套. 1 DROP TABLE #demo 2 CREATE TABLE #demo 3 ( 4 ZK_PLANNING_ID NVARCHAR(50), 5 ZK_PLAN_TITLE NV

&lt;06&gt;变量使用前易犯错误总结+if语句介绍及基本格式+if-else语句及嵌套+if语句的高级用法+if语句的使用注意点+arc4random_uniform 函数导入一个头文件&lt;stdlib.h&gt;+

1)变量要初始化 -1 0  ,或者1 依据程序而定 ---------------------------------- if语句介绍及基本格式 分支语句结构 1)if 格式: if(表达式/常量/变量){ 语句块1; } 原理: 1)先计算小括号中的表达式的值 真(1) 会执行 大括号中的语句 假(0) 不会执行 大括号中的语句 2) switch 1 #include <stdio.h> 2 3 int main(int argc, const char * argv[]) { 4 5

Java知多少(48)try语句的嵌套

Try语句可以被嵌套.也就是说,一个try语句可以在另一个try块内部.每次进入try语句,异常的前后关系都会被推入堆栈.如果一个内部的try语句不含特殊异常的catch处理程序,堆栈将弹出,下一个try语句的catch处理程序将检查是否与之匹配.这个过程将继续直到一个catch语句匹配成功,或者是直到所有的嵌套try语句被检查耗尽.如果没有catch语句匹配,Java的运行时系统将处理这个异常.下面是运用嵌套try语句的一个例子: 1 // An example of nested try s

Mysql update语句赋值嵌套与在表列中数据后面增加数据

1.Mysql update语句赋值嵌套select  点击(此处)折叠或打开 update a set col=(select col from a where id='5') where id>5 and id<10; 报错了 ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause 经过研究 发现是 mysql 定义update语句不能同时对同一张进行set 赋值操作,也就是说 upd

4.5 以卫语句取代嵌套条件式

[1]原代码 1 double GetPayAmount() 2 { 3 double result; 4 if (IsDead()) 5 { 6 result = DeadAmount(); 7 } 8 else 9 { 10 if (IsSeparated()) 11 { 12 result = SeparatedAmount(); 13 } 14 else 15 { 16 if (IsRetired()) 17 { 18 result = RetiredPayAmount(); 19 }

Java基础---Java条件语句之嵌套if(二十)

Java条件语句之嵌套 if 嵌套 if 语句,只有当外层 if 的条件成立时,才会判断内层 if 的条件.例如,活动计划的安排,如果今天是工作日,则去上班,如果今天是周末,则外出游玩:同时,如果周末天气晴朗,则去室外游乐场游玩,否则去室内游乐场游玩. 语法:  执行过程:  例如: 运行结果: 代码: public class Helloworld {            public static void main(String[] args) {          int score

简化条件表达式之以卫语句取代嵌套条件表达式(Replace Nested Conditional With Guard Clauses)

函数中的条件逻辑使人难以看清正常的执行途径.使用卫语句表现所有特殊情况. 动机:条件表达式通常有2种表现形式.第一:所有分支都属于正常行为.第二:条件表达式提供的答案中只有一种是正常行为,其他都是不常见的情况. 这2类条件表达式有不同的用途.如果2条分支都是正常行为,就应该使用形如if…..else…..的条件表达式:如果某个条件极其罕见,就应该单独检查该条件,并在该条件为真时立刻从函数中返回.这样的单独检查常常被称为“卫语句”. Replace Nested Conditional with

mybatis框架中parameterType为Map的用法 和 数据库语句多层嵌套

当需用到参数Map里面的数据时,直接写传进去的key,例Map map = new HashMap(); map.put("currPage1",10); 在mybatis的xml文件中需要引用的地方写上currPage1,如下文 数据库语句多层嵌套时,先执行最里层的语句,表的别名定义语句的最里层,红色字体是多表联查时定义的查询最大记录数 例: <select id="query" parameterType="java.util.Map"

慕课网-安卓工程师初养成-4-4 Java条件语句之嵌套 if

来源:http://www.imooc.com/code/1356 嵌套 if 语句,只有当外层 if 的条件成立时,才会判断内层 if 的条件.例如,活动计划的安排,如果今天是工作日,则去上班,如果今天是周末,则外出游玩:同时,如果周末天气晴朗,则去室外游乐场游玩,否则去室内游乐场游玩. 语法:  执行过程:  例如: 运行结果: 任务 请在代码编辑器中补全代码实现赛程设置:预赛成绩大于 80 分的可进入决赛,然后根据性别再划分为男子组决赛和女子组决赛. 运行结果为: 1 public cla