sqlÓï¾äµÄÎÊÌâ - MS-SQL Server / »ù´¡Àà
ÓÐ2¸ö±í°¡£º
±íÃû£ºyh
Óû§±àÂë Óû§Ãû³Æ
001 a
002 b
003 c
±íÃû£ºys
Óû§±àÂë ±¾ÆÚÖ¸Êý ³±íʱ¼ä
001 11 2009-01-13
001 2 2009-02-26
002 3 2009-01-13
002 1 2009-02-26
Á½¸ö±íµÄͨ¹ýÓû§±àÂë À´¹ØÁª£º
Ï£ÍûµÃµ½ÏÂÃæµÄ½á¹¹
Óû§±àÂë Óû§Ãû³Æ ±¾ÆÚÖ¸Êý
001 a 2
002 b 1
003 c 0
SQL code:
SELECT A.Óû§±àÂë,Óû§Ãû³Æ, ±¾ÆÚÖ¸Êý =COUNT(*)
from YH A,YS B
WHERE A.Óû§±àÂë=B.Óû§±àÂë
GROUP BY A.Óû§±àÂë,Óû§Ãû³Æ
SQL code:
select
yh.*,
isnull(ys.±¾ÆÚÖ¸Êý,0) as ±¾ÆÚÖ¸Êý
from
yh
left join
ys
on yh.Óû§±àÂë =ys.Óû§±àÂë
and not exists(select 1 from ys t where t.Óû§±àÂë=ys.Óû§±àÂë and t.³±íʱ¼ä>ys.³±íʱ¼ä)
select c.*,t.³±íʱ¼ä
from yb c,(
select *
from ys a
where not exists (select 1
from ys b
where a.Óû§±àÂë=b.Óû§±àÂë and a.³¬±êʱ¼ä<b.³±íʱ
Ïà¹ØÎÊ´ð£º
½«Ò»¸ö±í21~30ɾ³ý£¬sqlÓï¾äÔõôд
Õâ¸öÌ«ÁýͳÁË£¬ÊÇÅÅÐòºóµÄµÚ21Ìõµ½30Ìõ¼Ç¼ɾ³ý»¹ÊÇijһÁÐÖµÔÚ21µ½30Ö®¼äµÄɾ³ý°¡£¿
21-30ÊÇʲôÒâ˼£¿×ֶεϰ¾Ídelete from table1 where col1>=21 and col1<=30
Ö¸µ ......
Èç¹ûÓÃsqlÓï¾ä¸ü¸Älj×ֶεÄ·¾¶£¬ÈçÏ£º
lj
7/200781616183095962.jar
8/f_200812111413292.jar
8/f_200812111413291.jar
µÃµ½µÄ½á¹ûÈçÏ£º
lj
1/7/200781616183095962.jar
1/8/f_20081 ......
ÓÐÒ»Õűí(SHGL)
JLBH LXR LXDH SHDZ
1 a ......
pl/SqlÈçºÎ²éѯ×Ö·û´®°üÀ¨%,
ÀýÈç:TABLE a
columnA
'222'
'33%44'
ÈçºÎ²éѯ±íaÖÐcolumnA×Ö¶ÎÖÐÄÄЩÐаüº¬'%'
лл
select * from a
where columna like '%/%%' escape '/'
UP
SELECT * from a ......