ÇóÒ»¸´ÔÓsqlÓï¾ä - MS-SQL Server / »ù´¡Àà
id stucode stuaddress sturoom stutime
1 22 35# n502 201005
2 22 35# n502 201007
3 12 45# n501 201005
4 22 35# n502 201005
5 22 35# n502 201005
6 12 45# n501 201009
7 12 65# n401 201010
8 22 35# n502 201005
9 22 34# n502 201005
10 32 35# n512 201005
11 22 34# n502 201007
12 32 55# n512 201009
13 33 55# n512 201009
ÇóÒ»sqlÓï¾äµÃµ½½á¹ûÈçÏÂ:
code address room time
22 35# n502 201007
12 45# n501 201009
32 55# n512 201009
33 55# n512 201009
codeΪ»ù´¡,È»ºó¶Ô±Èaddress+room °ÑÏàͬÌõÄ¿¶àµÄÁôÏÂ,×îºóÖ»ÁôÏÂÒ»Ìõtime×î´óµÄ.
ÔÔòÒ»:22µÄ 35#+n502 ÓÐ4Ìõ, 22µÄ34#+n502 ÓÐ2Ìõ ËùÒÔÁôÏÂ22µÄ 35#+n502,È»ºóÔÙÊ£ÏÂʱ¼ä×î´óµÄÒ»Ìõ
22 35# n502 201007
ÔÔò¶þ:32µÄ55#+n512 ÓÐ1Ìõ, 32µÄ35#+n512ÓÐ1Ìõ Áôʱ¼ä×î´óµÄÒ»Ìõ,Èç¹ûʱ¼äÏàͬÁôid´óµÄ,idΨһ
32 55# n512 201009
ms sql ÔÚmy sqlÖб¨´í mysqlÔõôд? ÒÔÏÂΪÓï¾ä
with cte as(
select *
,count(stuaddress+sturoom) over(partition by stucode,stuaddress+sturoom) as cnt
,max(stutime) over(partition by stucode,stuaddress+sturoom) as mx_time
from #test)
select stucode,stuaddress,sturoom,stutime from cte a where stutime=mx_time
and not exists(select 1 from cte
where stutime=mx_time
and(( a.stucode=stucode and a.cnt=cnt and a.stutime<stutime)
or ( a.stucode=stucode and
Ïà¹ØÎÊ´ð£º
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Ä ......
´ÓÊý¾Ý¿âÖвéѯһÕűíµÄÊý¾Ý
select ²¿ÃÅ,ÐÕÃû from tb
ÈçºÎ²ÅÄÜÉú³ÉÏÂÃæµÄxml¸ñʽ
XML code:
<folder state="unchecked" label="È«²¿">
¡¡¡¡ <folder state="unchecked&qu ......
ÈçºÎÔÚSQL2005ÖÐÉ趨¶¨Ê±×÷Òµ£¬±ÈÈç˵¶¨Ê±ÇåÀíijЩ±íµÄÊý¾Ý£¬
»òÕßÊǶ¨Ê±µÄ½«Ä³Ð©±íµÄÊý¾Ýµ¼³öexcel£¡
ÔÚÏߵȴý£¬¼±¼±¼±£¬×îºÃÊÇÏêϸ²½Ö裡
֮ǰÎÒ×öµÄ×÷ÒµÓеãÎÊÌ⣡
°ïUP
²Î¿¼:http://hi.baidu.com/toiota ......
tab1 ×Ö¶Î:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 ×Ö¶Î:goodsid,goodskind£¨ÉÌÆ·ÀàÐÍ£©
tab3 ×Ö¶Î:goodskind£¨ÉÌÆ·ÀàÐÍ£©,kindname
½á¹û£º
µÃµ½ÉÌÆ·ÀàÐÍÔÚÒ»¶Îʱ¼ä ......
Çó¸övbÖеÄsqlÓï¾äµÄд·¨£¬´ÎsqlÓï¾äµÄÓ÷¨ÊÇ·ÖÒ³³ÌÐò
ÎÒдµÄÈçÏ£ºÆäÖÐAÊÇÓÃÀ´½ÓÊÕÿҳÏÔʾµÄ¼Ç¼µÄÌõÊý£¬BÊÇÓÃÀ´½ÓÊÕÏÔʾµÄµ±Ç°µÄÒ³Ãæ.
sqltext="select top A * from log where id not in(select top ( ......