`

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 ...

    BC305--SAP BASIS

    Position your cursor on the change request number created by Group A in exercise 8.1. Choose Request  Import. Choose Continue and confirm if necessary. After the change request is successfully ...

    Go: Design Patterns for Real-World Projects

    Next, you will get familiar with the tools and libraries that are available in Go to write and exercise tests, benchmarking, and code coverage. After that, you will be able to utilize some of the ...

    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 ...

Global site tag (gtag.js) - Google Analytics