sql学习相关
文章平均质量分 62
kourr2004
这个作者很懒,什么都没留下…
展开
-
各位老大帮忙啊,季度汇总啊,怎么写啊,感谢
select 一季=sum(case when datepart(quarter, 日期)=1 then 金额 else 0 end),二季=sum(case when datepart(quarter, 日期)=2 then 金额 else 0 end),三季=sum(case when datepart(quarter, 日期)=3 then 金额 else 0 end),四季=sum(cas转载 2007-09-21 15:54:00 · 381 阅读 · 0 评论 -
取这样的数据(a,b,c)变成(a代表的意思,b代表的意思,c代表的意思)方法
---创建测试环境 Create Table Tags(ID int,Name Varchar(20)) Insert Tags Select 1, Tag1 Union All Select 2, Tag2 Union All Select 3, Tag3 Union All Select 4, Ta转载 2007-10-01 11:05:00 · 743 阅读 · 0 评论 -
SQL 面试题
http://www.xiejianli.net/mianshiti/276/876.htm(转贴地址)假设只有一个table,名为pages,有四个字段,id, url,title,body。里面储存了很多网页,网页的url地址,title和网页的内容,然后你用一个sql查询将url匹配的排在最前,title匹配的其次,body匹配最后,没有任何字段匹配的,不返回。就是上面这道面试转载 2007-10-01 10:08:00 · 618 阅读 · 0 评论 -
某外企SQL Server面试题(英文,答案)
Question 1:Can you use a batch SQL or store procedure to calculating the Number of Days in a Month Answer 1:找出当月的天数select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar转载 2007-10-01 10:28:00 · 1380 阅读 · 0 评论 -
关于如何只取得每组数据中的一个最大值的问题?
create table topic(Topicid int,title nvarchar(10),boardid int,addtime datetime )insert topic select 1, abc, 100, 2007-1-1 union all select 2, era, 101,转载 2007-10-01 13:38:00 · 886 阅读 · 0 评论 -
left join使用精华:)
create table tt( id int identity(1,1), name varchar(10))insert ttselect a union allselect b union allselect ccreate table tt1( id int identity(1,1), name varchar(10))insert tt1select a u转载 2007-09-21 16:10:00 · 1586 阅读 · 2 评论 -
简单的最大最小问题:)
例表tb:id price netprice1 8.00 20.002 10.00 5.003 0.00 3.00 我想要查出price与netprice之间大的列比如查出如下数据:id newprice1 20.002 10.003 3.00sql语句要怎么写?Create Table tb(id Int, pric原创 2007-09-21 10:41:00 · 462 阅读 · 0 评论 -
删除以"temp"开头的所有表
declare @sql varchar(8000)set @sql=select @sql=@sql+,+name from sysobjects where type=U and name like temp%set @sql=drop table +stuff(@sql,1,1,) --去掉开头一个","exec(@sql)--例如:print @sql =dr原创 2007-09-21 11:04:00 · 752 阅读 · 0 评论 -
1亿条数据中保留5条删除其他的有什么快点的方法:)
1、 select * into #test from table_Pqs where ...(5条记录) --先把5条数据导入临时表,这样的语句是表示连表结构也复制2、 truncate table table_Pqs --再把原表中数据truncate掉3、 Insert Into table_Pqs select * from #test --再把临时表中的数据导入表中4、 Drop ta转载 2007-09-21 10:30:00 · 705 阅读 · 1 评论 -
怎样取得表中不存在月份数据?
--测试数据declare @T table(yd varchar(10),rs int)insert @Tselect 2006-1,5 union allselect 2006-2,8 union allselect 2006-5,10 union allselect 2006-8,3 union allselect 2006-12,10select top 12 mon=转载 2007-10-15 10:43:00 · 506 阅读 · 0 评论