Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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±íʾ¼°¸ñ£¬Ð¡Ó


Ïà¹ØÎĵµ£º

SQL SERVER 2005 ͬ²½¸´ÖƼ¼Êõ

SQL SERVER 2005 ͬ²½¸´ÖƼ¼Êõ
ÒÔÏÂʵÏÖ¸´ÖƲ½Ö裨ÒÔ¿ìÕÕ¸´ÖÆÎªÀý£©
ÔËÐÐÆ½Ì¨SQL SERVER 2005
Ò»¡¢×¼±¸¹¤×÷£º
1£®½¨Á¢Ò»¸ö WINDOWS Óû§£¬ÉèÖÃΪ¹ÜÀíԱȨÏÞ£¬²¢ÉèÖÃÃÜÂ룬×÷Ϊ·¢²¼¿ìÕÕÎļþµÄÓÐЧ·ÃÎÊÓû§¡£
2£®ÔÚSQL SERVERÏÂʵÏÖ·¢²¼·þÎñÆ÷ºÍ¶©ÔÄ·þÎñÆ÷µÄͨÐÅÕý³££¨¼´¿ÉÒÔ»¥·Ã£©¡£´ò¿ª1433¶Ë¿Ú£¬ÔÚ·À»ðǽÖÐÉèÌØÀ ......

SQL ServerÊý¾Ý¿â¾µÏñÅäÖò½Öè

Ò»¡¢Ê¹ÓÃÖ¤ÊéʵÏÖÖ÷±¸SQL ServerʵÀýµÄ»¥Í¨
1.ÔÚÖ÷»úºÍ±¸»úÉϷֱ𴴽¨Ö¤Êé
ÔÚÖ÷»úÉÏÖ´ÐÐÈçÏÂÓï¾ä:
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'abcdefg';
CREATE CERTIFICATE CERT_HOST_A WITH SUBJECT = 'HOST_A certificate' ,
START_DATE = '01/01/2010';
GO
ÔÚ±¸»úÉÏÖ´ÐÐÈçÏÂÓï¾ä:
USE master; ......

sql´æ´¢¹ý³Ì¶ÁÈ¡ÐÅÏ¢ÖÐÎÊÌâ

sql="select * from (select top 4 ID,SmallPic,NewsNameSi,EndDate,ContentSi,SortID from achi_news where ProductProperty=1 and IsOk=1 and HomeForcePage=1 and HomeEndTime>getDate() and isdate(HomeEndTime)=1 order by HomeorderNum asc  )a union all select * from (select top 4 ID,SmallPic,NewsNameS ......

SQL ×óÓÒÁ¬½Ó

 ±¾ÎÄ×ªÔØÓÚ£ºhttp://www.javaeye.com/topic/185385
ѧϰÊý¾Ý¿â²éѯµÄʱºò¶Ô¶à±íÁ¬½Ó²éѯµÄÓÐЩ¸ÅÄ±È½ÏÄ£ºý¡£¶øÁ¬½Ó²éѯÊÇÔÚÊý¾Ý¿â²éѯ²Ù×÷µÄʱºò¿Ï¶¨ÒªÓõ½µÄ¡£¶ÔÓڴ˸ÅÄî
ÎÒÓÃͨË×һЩµÄÓïÑÔºÍÀý×ÓÀ´½øÐн²½â¡£Õâ¸öÀý×ÓÊÇÎÒ½²¿ÎµÄʱºò¾­³£²ÉÓõÄÀý×Ó¡£
Ê×ÏÈÎÒÃÇ×öÁ½ÕÅ±í£ºÔ±¹¤ÐÅÏ¢±íºÍ²¿ÃÅÐÅÏ¢±í£¬ÔÚ´Ë£¬±íµ ......

SQLÉú³ÉÁ÷Ë®ºÅ

¾­¹ýÁ˼¸´ÎµÄ²âÊÔÖÕÓڳɹ¦ÁË
declare @Year Int,
        @Month int,
        @Day int,
        @Temp_No varchar(12),
        @NeedNo varchar(4),
   ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ