`

basis and exercise

阅读更多

select now();
select CURDATE();
insert into pa_login_logs(party_no, login_time) values(3,now());
SELECT *,max(login_time) FROM pa_login_logs group by party_no order by max(login_time) desc;

 

 

5.有一张表格s_su,有三个字段age,name,score ,现在根据要求写出SQL语句:
1),根据年龄分组,选出分数score>90的分组的年龄分组和同学个数。
select age,count(*) from s_su where scoure >90 group by age;
2),根据年龄分组,选出平均分大于85的分组的年龄分组和平均分。
select age,avg(scoure) from s_su group by age having avg(scoure) >90;
3),假设这个表有100条记录,用SQL语句打印出分页记录,打印出第50-60的记录.
Mysql:select * from s_su limit 50,60;
----》这个主要考到分组和使用函数,另外使用having挑选出适合的分组。至于limit是Mysql专业函数,其他数据库不知道能不能通用,大家可以测试下。

6.假设表A有6条记录,B有4条记录,进行匹配的字段为name,看下面SQL语句给出结果:
1),select * from A left join B on A.name = B.name,最多有几条记录,最少呢?
答,最多和最少都是6条。
2),select * from A right join B on A.name = B.name,最多有几条记录,最少呢?
答,最多和最少都是4条。
3),select * from A left jion B on A.name = B.name union select * from A left jion B on A.name = B.name,最多有几条记录,最少呢?
答,最多和最少都是6条。
4), select * from A left jion B on A.name = B.name union select * from B left jion A on B.name = A.name, 最多有几条记录,最少呢?
答:最多有10条,最少有6条。
5), select * from A left jion B on A.name = B.name union all select * from A left jion B on A.name = B.name ,最多有几条记录,最少呢?
答:最多和最少都是12条。
6), select * from A left jion B on A.name = B.name union select * from B left jion A on B.name = A.name, 最多有几条记录,最少呢?
答:最多和最少都是10条。
----》这里考到Sql语句中左联和右联,左联就是以左边作为基准,有的值保留,没有的话就为Null,右联也是如此。现在主要是union和union all的问题了,union是将相同的进行合并,不相同的向左边基准表插入,union all则是不管相同与否都是向左基准表插入。

 

 

 

 

分享到:
评论

相关推荐

    Fundamentals of wavelets theory algorithms and applications

    2.4 Local Basis and Riesz Basis. 2.5 Discrete Linear Normed Space. 2.6 Approximation by Orthogonal Projection. 2.7 Matrix Algebra and Linear Transformation. 2.8 Digital Signals. 2.9 Exercises. 2.10 ...

    neural-net-rbf-master.zip

    In this exercise you will experiment with Radial-Basis Functions (RBFs). RBF networks is a neural network type which can be used for classication as well as function approximation. During this ...

    Physically Based Rendering from Theory to Implementation - part1

    Theoretical Basis for Particle Tracing † Photon Integrator Building the Photon Maps Using the Photon Map Photon Interpolation and Density Estimation Further Reading Exercises CHAPTER 17. ...

    微软内部资料-SQL性能优化2

    Troubleshooting server performance-based support calls requires product knowledge, good communication skills, and a proven troubleshooting methodology. In this module we will discuss Microsoft® SQL ...

    Struts2上传所需jar包

    risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or ...

    struts1.3.9.zip

    risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or ...

    Vagaa哇嘎画时代--体验群体智慧的力量!

    4.1 You are responsible for paying all applicable taxes and other costs you may incur in connection with your use of the Software including but not limited to all hardware and software costs and ...

    Recover4all Professional

    Please read the following terms and conditions carefully because they will apply to Your use of both the unregistered and registered versions of the software program Recover4all(tm) Professional and ...

    netWindows_0.3.0_pre2

    This License shall terminateautomatically and You may no longer exercise any of the rights granted to Youby this License if You file a lawsuit in any court alleging that any OSICertified open source ...

    SAP ADM510

    ### SAP ADM510: SAP ERP ADM Basis 详解 #### 一、课程概述与数据库概览 ##### 1.1 课程概述 SAP ADM510 课程旨在为学员提供全面深入的学习体验,主要围绕SAP NetWeaver平台下的Oracle数据库管理进行讲解。该...

    人教英语必修二Unit复习PPT课件.pptx

    - `basis`: 基础,复数形式为`bases`,动词表示基于为`base on/based on`。 - `athlete`: 运动员,形容词形式为`athletic`,表示擅长运动的。 通过这份课件,学生不仅可以学习到丰富的词汇,还可以了解如何运用...

    大学课程中英文名称对照大全

    * Hopf 代数与代数群量子群:Hopf Algebra , Algebraic Group and Quantum Group,介绍了Hopf代数在代数群和量子群中的应用。 其他 * CET-4 College English Test (Band 4):介绍了大学英语四级考试的基本概念和...

    机械类的英文课程.doc

    20. **机械设计 (Mechanical Designing)** 和 **机械设计基础 (Basis of Mechanical Designing)**:教授设计过程、工程材料选择、强度计算和结构优化。 21. **机械设计课程设计 (Course Exercise in Mechanical ...

    英语四级常考词汇频率统计

    例句:*The heart rate increased during exercise.*(运动时心率增加。) - **rank**:排名、等级;例句:*The student ranked first in the class.*(这名学生在班里排名第一。) - **range**:范围、变动;例句:...

Global site tag (gtag.js) - Google Analytics