ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

¤À²Õ«e¤T¦W»yªk

¦^´_ 2# stillfish00

·PÁ¤j¤j´£¨Ñªº¤èªk¡A³o¼Ëªº¦ê±µªk¡A¦b¤pµ§¼Æ®É¡AÀ³¸ÓÁÙ¦æ¡A¦pªG¬O30¸Ux30¸U³o¼Ë¦ê´N¤£¤Ó¦n¡I

¥Ø«e¬O§Q¥ÎsqlŪ¥X30¸Uµ§¡A¥Îvba¥H°j°éªº¤è¦¡¡A¦pªG¬O«e¤T¦Wªº´N«O¯d¡A±q30¸Uµ§¤¤§ä¥X¨Ó©ñ¶iexcel¤¤¡A³o¼Ë¤£¥Î´X¬í

¥u¬O­Ó¤H°j°é¤è¦¡¼gªº¤£º}«G¡K
¥Ø«e¬Ý¨Ó¦b¸ê®Æ®w¤¤¦³¤À²Õ«á¨ú±Æ¦W­È¥\¯àªº
oracle
sql server
postgresql
¥»¨Ó·QÂà¹L¥h¥Î¡A¤£¹Lpostgresql³s±µvba
§ÚÁÙ¤£¦æ
©Ò¥H¥Ø«eÁÙ¥ý³o¼Ë¥Î

TOP

¦^´_ 1# joey0415

¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim AR(), E As Variant, Rng As Range
  4.     With Sheets("Sheet1")
  5.         .Range("A1").CurrentRegion.Sort Key1:=.Range("B2"), Order1:=xlAscending, Key2:=.Range( _
  6.         "A2"), Order2:=xlAscending, Key3:=.Range("D2"), Order3:=xlDescending, Header:=xlYes
  7.         '.Range("A1").CurrentRegion.Sort"¸ê®Æªº±Æ§Ç
  8.         .UsedRange.Columns(2).AdvancedFilter xlFilterCopy, , .Cells(1, .Columns.Count), True
  9.         'UsedRange.Columns(2)ªº¶i¶¥¿z¿ï->  ¤£­«½ÆªºªÑ²¼
  10.         
  11.         '**¤T¤Q¸Uµ§¸ê®Æ ³o¨â¦æ·|ºC¤@ÂI
  12.         
  13.         AR = Application.Transpose(.Cells(1, .Columns.Count).CurrentRegion.Offset(1))
  14.         '¨ú±oªÑ²¼¸m¤J¤@ºû°}¦C¤¤
  15.         ReDim Preserve AR(1 To UBound(AR) - 1)          '§R°£³Ì«á¤@µ§ªº(ªÅ¥Õ)¸ê®Æ
  16.         .Cells(1, .Columns.Count).CurrentRegion.Clear   '²M°£
  17.         .Range("F1").CurrentRegion.Offset(1).Clear      '²M°£Åã¥Ü«e¤Tµ§¸ê®Æªº°Ï°ì
  18.         For Each E In AR
  19.             Set Rng = .Range("B:B").Find(E, LookAT:=xlWhole)  '§ä¨C¤@ªÑ²¼ªº²Ä¤@­Ó¦ì¸m
  20.             .Range(.Cells(Rng.Row, "A"), .Cells(Rng.Row + 2, "D")).Copy .Cells(.Rows.Count, "F").End(xlUp).Offset(1)
  21.         Next
  22.     End With
  23. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 1# joey0415
sql¤À²Õ»yªk¡A¸Õ¬Ý¬Ý
  1. SELECT a.¤é´Á,a.ªÑ²¼,a.¨é°Ó,a.¼Æ¶q, COUNT(*) AS ±Æ¦W
  2. FROM ¸ê®Æªí as a
  3. INNER JOIN ¸ê®Æªí as b
  4. ON (a.ªÑ²¼=b.ªÑ²¼) AND (a.¼Æ¶q<=b.¼Æ¶q)
  5. GROUP BY a.¤é´Á,a.ªÑ²¼,a.¨é°Ó,a.¼Æ¶q
  6. HAVING COUNT(*) <=3
  7. ORDER BY a.ªÑ²¼,COUNT(*)
½Æ»s¥N½X
¤£¹L¤T¤Q¸Uµ§.....¡A§Ú¤£ª¾³o¼Ëªº»yªk®Ä²v¬O¤£¬O¨¬°÷ = =

TOP

        ÀR«ä¦Û¦b : ¦Û¤v®`¦Û¤v¡A²ö¹L©ó¶ÃµoµÊ®ð¡C
ªð¦^¦Cªí ¤W¤@¥DÃD