Çë°ÑÎÒµÄSQL ´úÂë·Åµ½²éѯ·ÖÎöÆ÷Àï¡£ È»ºó°´ÎÒ˵µÄÔËÐУ¬¸æËßÎÒ ÎÒÎʵÄÎÊÌ⣬лл¸ßÊÖÁË if not object_id('ta') is null drop table ta Go Create table ta([product] nvarchar(2),[spec] nvarchar(2)) Insert ta select N'p1',N's1' union all select N'p1',N's2' union all select N'p1',N's3' union all select N'p2',N's£µ' union all select N'p2',N's4' Go select * from ta t where [spec] = (select top 1 [spec] from ta where [product]=t.[product] order by newid())
ÎÊÌâ1 ÎÒ°Ñ [spec] = ÀïµÄµÈºÅ»»³É in ¶à´Î°´F5ÔËÐкó ¾Í»á³öÏÖÌõÊý 0µ½5ÌõÖ®¼äΪʲô¡£ÎÒÈÏΪ Õâʱºò=ºÅÓ¦¸ÃºÍinÊÇÒ»¸ö½á¹û£¬ÎÒtop1ÁË£¬ inºÍ newid ÓÐʲô³åÍ»Â𣿠ÎÊÌâ2 ÎÒ°Ñ = ¸Ã³É in ºó ÎÒ°Ñnewid() ¸Ã³É¹Ì¶¨ÁбÈÈçspec F5ºó ÌõÊý¾ÍÒ»ÑùÁË¡£ÎªÊ²Ã´¡£ Èç¹û»Ø´ðµÄÇå³þ£¬ÎÒ×·¼Ó·Ö¡£ ¡£Ð»Ð»ÒòΪspecÓÐÖØ¸´Öµ¡£ [spec]µÄÖµÓÐÖØ¸´ specÓÐÖØ¸´Öµ 1 2 Â¥µÄ£¬ ÄãÔËÐÐÎÒµÄÊý¾ÝÁËÂ𣿠spec ÊÇ´Ós1 µ½s5 Äã˵µÄÖØ¸´ÖµÎÒû¶® UP = ¸ú in Ö®¼äÊÇÓвî±ðµÄ.
select count(1) from FX_RETURNBOOKCHECKLIST fxreturnbo0_ where fxreturnbo0_.BOOKID='164 ' AND fxreturnbo0_.RETURNID='00025.S0000001' ÉÏÃæÒ»¸ö¼òµ¥µÄSQL,Ö´ÐÐʱ¼ä2.6à ......
µÚÒ»¾ä: select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je from ht left join gfdm on ht.gfdm=gfdm.gfdm join jh on ht.htbh=jh.hth and ht.htbh not like'del%' and ht. ......