sqlÃæÊÔ
1.Ò»µÀSQLÓï¾äÃæÊÔÌ⣬¹ØÓÚgroup by
±íÄÚÈÝ£º
2005-05-09 ʤ
2005-05-09 ʤ
2005-05-09 ¸º
2005-05-09 ¸º
2005-05-10 ʤ
2005-05-10 ¸º
2005-05-10 ¸º
Èç¹ûÒªÉú³ÉÏÂÁнá¹û, ¸ÃÈçºÎдsqlÓï¾ä?
ʤ ¸º
2005-05-09 2 2
2005-05-10 1 2
------------------------------------------
create table #tmp(rq varchar(10),shengfu nchar(1))
insert into #tmp values('2005-05-09','ʤ')
insert into #tmp values('2005-05-09','ʤ')
insert into #tmp values('2005-05-09','¸º')
insert into #tmp values('2005-05-09','¸º')
insert into #tmp values('2005-05-10','ʤ')
insert into #tmp values('2005-05-10','¸º')
insert into #tmp values('2005-05-10','¸º')
1)select rq, sum(case when shengfu='ʤ' then 1 else 0 end)'ʤ',sum(case when shengfu='¸º' then 1 else 0 end)'¸º' from #tmp group by rq
2) select N.rq,N.勝,M.負 from (
select rq,勝=count(*) from #tmp where shengfu='ʤ'group by rq)N inner join
(select rq,負=count(*) from #tmp where shengfu='¸º'group by rq)M on N.rq=M.rq
3)select a.col001,a.a1 ʤ,b.b1 ¸º from
(select col001,count(col001) a1 from temp1 where col002='ʤ' group by col001) a,
(select col001,count(col001) b1 from temp1 where col002='¸º' group by col001) b
where a.col001=b.col001
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±íʾ¼°¸ñ£¬Ð¡Ó
Ïà¹ØÎĵµ£º
1. SQL Server 2000Êý¾Ý¿âÁ¬½Ó×Ö·û´®
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn = java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://Êý¾Ý¿â·þÎñÆ÷Ãû»òµØÖ·:1433; DatabaseName=Êý¾Ý¿âÃû", "Óû§Ãû", "ÃÜÂë");
Ëù ......
use master
go
if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[P_KillConnections]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[P_KillConnections]
GO
create proc P_KillConnections
@dbname varchar(200)
as
declare @sql nvarchar(500)
declare @spid nvar ......
µ÷ÊÔSQLÊý¾Ý£¬·¢ÏÖÊý¾Ý¼Ç¼¼¯Öظ´ÎÊÌ⣬ËùÒÔ£¬¼ÆËã³öµÄÊý¾Ý½á¹û±¶ÊýÎÊÌ⡣ͨ¹ýµ÷ÊÔSQL£¬·¢ÏÖÊÇÎïÁϵķÖÀà²úÉúÖظ´£»Ö®ËùÒÔ²úÉúÖظ´£¬ÎïÁϵķÖÀà±ê×¼²»Ò»Ñù£¬Óëʵ¼ÊµÄÒµÎñÓйء£³ÌÐòÖÐÒ»Ö±ÓÃÀà±ðÀ´Çø·ÖÀà±ð£¬¶øÕâÕÅ´Îʵ¼ÊÒµÎñ²»ÐèÒªÓëÀà±ðÓйأ¬ËùÒÔ£¬Ã»ÓжÔÓ¦µÄ¹ýÂËÌõ¼þ£¬ËùÓеÄÀà±ðÈ«²¿Ñ¡³öÀ´ÁË¡£È»ºó£¬°ÑÏÂÃæµÄºìÉ«×Ö¶Î×¢ ......
Ö±½ÓÔÚSQL²éѯ·ÖÎöÆ÷ÖжÁÈ¡EXCELÎļþÐèҪʹÓõ½OPENDATASOURCE¡£
µ«ÊÇʹÓÃËü֮ǰÐèÒª½øÐÐÅäÖÃһϡ£¼ÇµÃÈçÏÂÅäÖÃÊDZØÐëµÄ£º
1¡¢Ö´ÐÐÕâÁ½¸ö´æ´¢¹ý³Ì£º
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
ËüµÄ×÷Óãº
µÚÒ»¸öÊÇ£ºÊÇ·ñÖ§³Ö¸ß¼¶Ñ¡ ......