SAK }‘ŠÙ

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

SQL –â‚¢‡‚킹 - rollupAcubeAgrouping setsAhavingAusingAcrossAnatural

‚±‚ê‚ç‚Ì‹@”\‚ÍAOracle ê—p‚Ì‹C‚ª‚·‚éB(Oracle8i ˆÈ~?)

¡ROLLUP

  E¬Œv’l‚ðo—Í‚·‚éB

select •i”Ô, count(*), sum(Žó’”), avg(Žó’”) from Žó’m
  group by rollup(•i”Ô);

•i”Ô                 COUNT(*) SUM(Žó’”) AVG(Žó’”)
------------------ ---------- ----------- -----------
a001                       25       10562      422.48
b001                        7       16797  2399.57143
c001                        3        6010  2003.33333
                           35       33369       953.4

select “¾ˆÓæCD, •i”Ô, count(*), sum(Žó’”), avg(Žó’”) from Žó’m
  group by rollup(“¾ˆÓæCD, •i”Ô);

“¾ˆÓ •i”Ô                 COUNT(*) SUM(Žó’”) AVG(Žó’”)
---- ------------------ ---------- ----------- -----------
1000 a001                       22        6452  293.272727
1000 b001                        1        2000        2000
1000 c001                        2        4510        2255
1000                            25       12962      518.48
2000 a001                        3        4110        1370
2000 b001                        6       14797  2466.16667
2000 c001                        1        1500        1500
2000                            10       20407      2040.7
                                35       33369       953.4

¡CUBE

  E‚ ‚ç‚ä‚é‘g‚݇‚킹‚̬Œv’l‚ðo—Í‚·‚éB(ƒNƒƒXWŒv’l)

select •i”Ô, count(*), sum(Žó’”), avg(Žó’”) from Žó’m
  group by cube(•i”Ô);

•i”Ô                 COUNT(*) SUM(Žó’”) AVG(Žó’”)
------------------ ---------- ----------- -----------
a001                       25       10562      422.48
b001                        7       16797  2399.57143
c001                        3        6010  2003.33333
                           35       33369       953.4

select “¾ˆÓæCD, •i”Ô, count(*), sum(Žó’”), avg(Žó’”) from Žó’m
  group by cube(“¾ˆÓæCD, •i”Ô);

“¾ˆÓ •i”Ô                 COUNT(*) SUM(Žó’”) AVG(Žó’”)
---- ------------------ ---------- ----------- -----------
1000 a001                       22        6452  293.272727
1000 b001                        1        2000        2000
1000 c001                        2        4510        2255
1000                            25       12962      518.48
2000 a001                        3        4110        1370
2000 b001                        6       14797  2466.16667
2000 c001                        1        1500        1500
2000                            10       20407      2040.7
     a001                       25       10562      422.48
     b001                        7       16797  2399.57143
     c001                        3        6010  2003.33333
                                35       33369       953.4

¡GROUPING SETS

  Egrouping set ‚ÅŽw’肵‚½€–Ú‚Ì’l‚¾‚¯‚ð‚à‚Á‚Ä‚­‚銴‚¶B

select •i”Ô, count(*), sum(Žó’”), avg(Žó’”) from Žó’m
  group by grouping sets(•i”Ô);

•i”Ô                 COUNT(*) SUM(Žó’”) AVG(Žó’”)
------------------ ---------- ----------- -----------
a001                       25       10562      422.48
b001                        7       16797  2399.57143
c001                        3        6010  2003.33333



select “¾ˆÓæCD, •i”Ô, count(*), sum(Žó’”), avg(Žó’”) from Žó’m
  group by grouping sets(“¾ˆÓæCD, •i”Ô);

“¾ˆÓ •i”Ô                 COUNT(*) SUM(Žó’”) AVG(Žó’”)
---- ------------------ ---------- ----------- -----------
1000                            25       12962      518.48
2000                            10       20407      2040.7
     a001                       25       10562      422.48
     b001                        7       16797  2399.57143
     c001                        3        6010  2003.33333

¡CONNECT BY

  EŠK‘w–â‚¢‡‚킹‚ÉŽg‚¦‚éƒe[ƒuƒ‹‚ª‚È‚©‚Á‚½B
    ŽŸ‚ÍA’P‚È‚é\•¶—á‚Å‚·B

select •i”Ô, Žó’” from Žó’m
  connect by •i”Ô = “¾ˆÓæCD;

select •i”Ô, Žó’” from Žó’m
  connect by prior •i”Ô = “¾ˆÓæCD and Žó’” >= 1000;

¡HAVING

  EWŒvŒ‹‰Ê‚ɑ΂·‚é–â‚¢‡‚킹ðŒ‚ðŽw’è‚·‚éB

select “¾ˆÓæCD, •i”Ô, count(*), sum(Žó’”), avg(Žó’”) from Žó’m
  group by “¾ˆÓæCD, •i”Ô
  having sum(Žó’”) > 1000;

“¾ˆÓ •i”Ô                 COUNT(*) SUM(Žó’”) AVG(Žó’”)
---- ------------------ ---------- ----------- -----------
1000 a001                       22        6452  293.272727
1000 b001                        1        2000        2000
1000 c001                        2        4510        2255
2000 a001                        3        4110        1370
2000 b001                        6       14797  2466.16667
2000 c001                        1        1500        1500

¡USING

  E€–Ú‚ÅŒ‹‡‚·‚éB

select * from Žó’m left join “¾ˆÓæm
  using (“¾ˆÓæCD);

¡CROSS JOIN

  EOracle ‚Ìu,v•W‹L‚Æ“¯‚¶B(ƒNƒƒXŒ‹‡AƒNƒƒXƒWƒ‡ƒCƒ“)

select * from Žó’m cross join “¾ˆÓæm
  where Žó’m.“¾ˆÓæCD = “¾ˆÓæm.“¾ˆÓæCD;

¡NATURAL JOIN

  E“¯‚¶–¼‘O‚Ì—ñ‚ðŽ©‘RŒ‹‡‚·‚éB(ƒiƒ`ƒ…ƒ‰ƒ‹ƒWƒ‡ƒCƒ“)

select * from Žó’m natural left join “¾ˆÓæm;

¡SQL Šî‘bŽÀ’n•ÒŽ‘—¿
¡SQL Šî‘b•ÒŽ‘—¿
¡SQL ƒ`ƒ…[ƒjƒ“ƒO•ÒŽ‘—¿
¡Oracle PL/SQL •ÒŽ‘—¿
¡PostgreSQL •ÒAJAVA ServletAJSP •ÒŽ‘—¿
¡MySQL •ÒŽ‘—¿
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ



Copyright (C) 1999-2024 Y.SAK