几个经典sql
来源:互联网 发布:辐射4美女捏脸数据 编辑:程序博客网 时间:2024/06/18 11:05
几个经典的sql语句
1.关于group by的sql语句
表结构:
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1992 1 2.1
1992 2 2.2
1992 3 2.3
显示结果:
year m1 m2 m3
1991 1.1 1.2 1.3
1992 2.1 2.2 2.3
sql的写法:
select year,
(select amount from test as m where month='1' and test.year=m.year) as m1,
(select amount from test as m where month='2' and test.year=m.year) as m2,
(select amount from test as m where month='3' and test.year=m.year) as m3
from test group by year
2.请教一个面试中遇到的SQL语句的查询问题
表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
------------------------------------------
select (case when a>b then a else b end ),
(case when b>c then b esle c end)
from table_name
3.面试题:一个日期判断的sql语句?
请取出tb_send表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间)
------------------------------------------
select * from tb where datediff(dd,SendTime,getdate())=0
4.有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):?
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。?
显示格式:?
语文 数学 英语?
及格 优秀 不及格?
------------------------------------------
select
(case when 语文>=80 then '优秀'
when 语文>=60 then '及格'
else '不及格') as 语文,
(case when 数学>=80 then '优秀'
when 数学>=60 then '及格'
else '不及格') as 数学,
(case when 英语>=80 then '优秀'
when 英语>=60 then '及格'
else '不及格') as 英语,
from table
1.关于group by的sql语句
表结构:
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1992 1 2.1
1992 2 2.2
1992 3 2.3
显示结果:
year m1 m2 m3
1991 1.1 1.2 1.3
1992 2.1 2.2 2.3
sql的写法:
select year,
(select amount from test as m where month='1' and test.year=m.year) as m1,
(select amount from test as m where month='2' and test.year=m.year) as m2,
(select amount from test as m where month='3' and test.year=m.year) as m3
from test group by year
2.请教一个面试中遇到的SQL语句的查询问题
表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
------------------------------------------
select (case when a>b then a else b end ),
(case when b>c then b esle c end)
from table_name
3.面试题:一个日期判断的sql语句?
请取出tb_send表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间)
------------------------------------------
select * from tb where datediff(dd,SendTime,getdate())=0
4.有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):?
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。?
显示格式:?
语文 数学 英语?
及格 优秀 不及格?
------------------------------------------
select
(case when 语文>=80 then '优秀'
when 语文>=60 then '及格'
else '不及格') as 语文,
(case when 数学>=80 then '优秀'
when 数学>=60 then '及格'
else '不及格') as 数学,
(case when 英语>=80 then '优秀'
when 英语>=60 then '及格'
else '不及格') as 英语,
from table
0 0
- 几个经典的SQL
- 几个经典sql
- 觉得比较经典的几个SQL语句
- SQL Server BI的几个经典案例:Project Real等
- SQL Server 常用 几个设置(set)选项 [经典实用]
- 几个sql
- 经典小故事几个
- 几个经典问题
- 几个经典的游戏
- 几个经典的博弈
- SourceInsight几个经典用法
- 几个经典的博弈
- 几个经典的博弈
- 几个经典的故事
- 几个经典故事
- 几个经典的故事
- SourceInsight几个经典用法
- 几个经典汇编段子
- 三线程联系输出abc
- Android 多进程和多线程
- 最短编辑距离
- 设计模式-起点
- C语言函数总结
- 几个经典sql
- python获取当前 昨天 及所有时间
- sqoop导入数据至hive
- Spring事件机制
- python访问mysql
- webView的使用以及总结
- hive left outer join where 条件问题
- Kafka与其他消息组件对比
- 音频和视频播放