group by 随机数 查询保存到临时表

select * from dbo.Employee

insert into dbo.Employee  values 
('name9',10,'男',2,2, cast(ceiling(rand() *4000) as int)+1000),
('name10',10,'女',2,2,cast(ceiling(rand() *4000) as int)+1000),
('name11',10,'男',2,2,cast(ceiling(rand() *4000) as int)+1000),
('name12',10,'女',2,2,cast(ceiling(rand() *4000) as int)+1000),
('name13',10,'男',2,2,cast(ceiling(rand() *4000) as int)+1000),
('name14',10,'男',2,2,cast(ceiling(rand() *4000) as int)+1000),
('name15',10,'女',2,2,cast(ceiling(rand() *4000) as int)+1000)

select AVG(age) from dbo.Employee where sex='男'


select * from Employee m,Education d
	where m.Education=d.id
	and d.EduName='本科'
	
	select sex,MAX(e.Salary), MIN(e.Salary) from Employee e
		group by e.Sex
	
	--	男女各多少人
	select COUNT(1) ,sex 
		from Employee
		group by sex
	
	--	每个岗位有多少人
	select COUNT(1), j.JobName
		from Employee e,Job  j
		where e.Job=j.id
		group by j.JobName
	--	每个学历有多少人
	select COUNT(1),d.EduName
		from	Employee e, Education d
		where e.Education=d.id
		group  by d.EduName
	--	每个岗位每个月发多少钱
	select SUM(salary),j.JobName
		from Employee e,Job j
		where e.Job=j.id
		group by j.JobName
	
	--	那个岗位发的钱最多
	select top 1 SUM(salary),j.JobName
		from Employee e,Job j
		where e.Job=j.id
		group by j.JobName
		order by SUM(salary) desc
	
	
	
		
		-- 把查询到数据插入到一张表里面
		-- 如果表存在
			insert into [新表名]
				select [列名] from [原表名]
		-- 如果表不存在
			select [列名] into [新表名]
				from[原表名]
						

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值