Java面试需要知道的SQL语句语法(三)
来源:互联网 发布:螳螂饲养盒 淘宝 编辑:程序博客网 时间:2024/05/22 15:44
26、前10条记录
select top 10 * form table1 where 范围
27、选择在每一组b值相同的数据中对应的a最大的记录的所有信息(类似这样的用法可以用
于论坛每月排行榜,每月热销产品分析,按科目成绩排名,等等.)
select a,b,c from tablename ta where a=(select max(a) from tablename tb where
tb.b=ta.b)
28、包括所有在 TableA 中但不在 TableB和TableC 中的行并消除所有重复行而派生出一个
结果表
(select a from tableA ) except (select a from tableB) except (select a from tableC)
29、随机取出10条数据
select top 10 * from tablename order by newid()
30、随机选择记录
select newid()
31、删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by
col1,col2,...)
32、列出数据库里所有的表名
select name from sysobjects where type='U'
33、列出表里的所有的
select name from syscolumns where id=object_id('TableName')
34、列示type、vender、pcs字段,以type字段排列,case可以方便地实现多重选择,类似
select 中的case。
select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C'
then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename
group by type
显示结果:
type vender pcs
电脑 A 1
电脑 A 1
光盘 B 2
光盘 A 2
手机 B 3
select top 10 * form table1 where 范围
27、选择在每一组b值相同的数据中对应的a最大的记录的所有信息(类似这样的用法可以用
于论坛每月排行榜,每月热销产品分析,按科目成绩排名,等等.)
select a,b,c from tablename ta where a=(select max(a) from tablename tb where
tb.b=ta.b)
28、包括所有在 TableA 中但不在 TableB和TableC 中的行并消除所有重复行而派生出一个
结果表
(select a from tableA ) except (select a from tableB) except (select a from tableC)
29、随机取出10条数据
select top 10 * from tablename order by newid()
30、随机选择记录
select newid()
31、删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by
col1,col2,...)
32、列出数据库里所有的表名
select name from sysobjects where type='U'
33、列出表里的所有的
select name from syscolumns where id=object_id('TableName')
34、列示type、vender、pcs字段,以type字段排列,case可以方便地实现多重选择,类似
select 中的case。
select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C'
then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename
group by type
显示结果:
type vender pcs
电脑 A 1
电脑 A 1
光盘 B 2
光盘 A 2
手机 B 3
手机 C 3
35、初始化表table1
TRUNCATE TABLE table1
阅读全文
0 0
- Java面试需要知道的SQL语句语法(三)
- Java面试需要知道的SQL语句语法(一)
- Java面试需要知道的SQL语句语法(二)
- java面试必须要知道的SQL语法,语句
- java面试必须要知道的SQL语法,语句
- Java面试必须要知道的SQL语法,语句
- Java面试必须要知道sql语法,语句
- 面试必须要知道的SQL语法,语句
- 面试必须要知道的SQL语法,语句
- 面试必须要知道的SQL语法,语句
- 面试必须要知道的SQL语法
- 面试必须知道的sql语句
- 学习SQL应知道的动态SQL语句基本语法
- 学习SQL应知道的动态SQL语句基本语法
- 学习SQL应知道的动态SQL语句基本语法
- 学习SQL应知道的动态SQL语句基本语法
- 学习SQL应知道的动态SQL语句基本语法
- 学习SQL应知道的动态SQL语句基本语法
- 棋牌游戏服务器-数据同步和持久化
- raspberry开机启动python
- 验证码 cookie倒计时
- redis知识盘点【肆】_主从复制和sentinel哨兵
- ReactNative之fetch请求报错解决
- Java面试需要知道的SQL语句语法(三)
- [PhalApi实战篇(1)]Redis队列处理异步任务
- 聊一聊全景图
- 每天回顾linux命令(time)
- FaceID调用的几个注意点
- 美素数
- Java Post请求 传递Json参数
- hdu5968(组合数取模Lucas定理)
- Extjs6.2 中使用 UEditor