Tutorial DãLINQããããããåºã¦ããªããã¨ããã®ã¯æ¬å½ã¯æ£ãããªããã©ãããã°ã©ãã³ã°è¨èªã«ã¤ãã¦ã¯éå¿çãªãã®ããåè«ã¿ãããªãã®ã¾ã§è²ã
ãªè¨èªãæ¥ã
ä½ããã¦ããã®ã¨æ¯è¼ããã¨ãé¢ä¿ãã¼ã¿ãã¼ã¹åãã®è¨èªã¯å
¨ç¶åºã¦ããªãã¨ããå°è±¡ãããã
æ³¢ã«ãã³ã¨begin endã®ã©ã¡ãããããã¨ãã³ãã³ã¯ã¿ã¼ããã¼ã¿ã¨ã»ãã¬ã¼ã¿ã®ã©ã¡ãã表ãã®ããããã¨ãã§ããè°è«ãçºçããã®ã«æ¯ã¹ãã¨ããã¼ã¿ãã¼ã¹è¨èªã«ã¤ãã¦ã¯SQLã®åé¡ç¹ã¨ã代ããã®è¨èªã¨ãã£ã話ã¯ã»ã¨ãã©èããªãã
é¢ä¿ãã¼ã¿ãã¼ã¹ã®åºæ¬ã¢ã¤ãã¢ã¯(コッドの論文ããã¼ããã«æãåºãã°)ã
- ãã¼ã¿ãé¢ä¿(ç´ç©éåã®é¨åéå)ã§è¡¨ç¾ãã
- åãåãã(ã¯ã¨ãª)ã¯ãéåæ¼ç®(é¢ä¿ä»£æ°æ¼ç®)ã«ãã£ã¦ãããªã
ã§ã ãã®æå°éã®æ©è½ãå®ç¾ãããªã¢ãã£è¨èªãä½ãã®ã¯ããã»ã©å¤§å¤ã§ã¯ãªãããã«æãããé¢ä¿ãã¼ã¿ã¯ã¿ãã«(é
å)ã®åã§è¡¨ç¾ããã°ããããããã¸ã®æä½(é¢ä¿ä»£æ°æ¼ç®)ãç´ æ´ã«å®è£
ããã°ããããããã°ã©ãã³ã°è¨èªAWKãã®ç¬¬4ç« ãã¬ãã¼ãã¨ãã¼ã¿ãã¼ã¹ãã§ãæ°ãã¼ã¸ã§åç´ãªæ©è½ã解説ã»å®è£
ãã¦ããã
ã¨ãããå±æ§å(ã«ã©ã å)ã®ããã«è©±ãé¢åã«ãªãã
å±æ§åã®å¯ä¸æ§
æ®éã®éåæ¼ç®ã§ã¯ã¿ãã«ã®åæåãæ°å(ä½çªç®ã®æåã)ã§åºå¥ããã®ã ãã©ãé¢ä¿ãã¼ã¿ãã¼ã¹ã§ã¯æ®éãåæåã«åå(å±æ§åãã«ã©ã å)ãä¸ãã¦åºå¥ãããããã ããªãã¿ãã«ãæ§é ä½ã(ãªãã¸ã§ã¯ãæåè¨èªã§ãã)ãªãã¸ã§ã¯ãã«ç½®ãæããã°æ¸ãã
ã§ãé¢ä¿ä»£æ°ã®å ´åãé¢ä¿ã®çµåãç´ç©ãããã¨æ°ããåã®ã¿ãã«ãä½ããããã®ã¨ãå±æ§åãéè¤ãã¦ãã¾ãå¯è½æ§ããããããã«ä½ããã®å¯¾å¦ãããå¿
è¦ãããã
ä¾ãã°ä¿³åªpersonã¨ç»å ´äººç©charactorã¨ããäºã¤ã®é¢ä¿ãã¼ã¿ã®èªç¶çµåãèãã(personã®nameã¨charactorã®castã«ã¤ãã¦çµåãã)ã
person
name | age |
charactor
name | age | cast |
Tutorial Dã§ã¯ãååã®éè¤ãèµ·ãããªãããã«çµååã«å±æ§åãå¤æ´ãã¦ããå¿ è¦ããããã¾ãèªç¶çµåã¯ãåãååã®å±æ§ã«å¯¾ãã¦ãããªãããã
person rename(prefix "" as "p_") join charactor{age, cast} rename(age as c_age, cast as p_name)
çµåã®çµæã次ã®ãããªé¢ä¿ãä½ãããã
p_name | p_age | c_age |
SQLã§ã¯ãå±æ§(ã«ã©ã )ã«ååãã¤ãã¦ããªãã¦ãæ§ããªãã
ããã§ã¯ãçµæã®å±æ§å(ããæ£ç¢ºã«ã¯ãåå)ãæå®ããã¨ããåé¡ã«ãSQLã¯ã©ã®ããã«å¯¾å¦ããã®ããçãã¯ãããã¡ãã¨å¯¾å¦ããªããã§ããã(C.J.Dateããã¼ã¿ãã¼ã¹å®è·µè¬ç¾©ã)
select person.name, person.age charactor.age from person, charactor where person.name = charactor.cast;
person.name | person.age | charactor.age |
ãã¼ãã«åã«ãã修飾(ãperson.ãããcharactor.ãã®é¨å)ã¯ã«ã©ã åã®ä¸é¨ã§ã¯ãªã(ã¯ã)ãªã®ã§ãå±æ§åã®å¯ä¸æ§ãæãç«ã£ã¦ããªãã
ä»ã«ãæ°ããå±æ§ã追å ããå ´åããTutorial Dã§ã¯å±æ§åãå¿
é ã ãã©ãSQLã§ã¯ãªãã¦ãããã
Tutorial D
extend person add(age - 1 as fudged_age)
name | age | fudged_age |
select name, age, age - 1 from person;
name | age | ã |
SQLã§ã¯ãã«ã©ã åã®å¯ä¸æ§ãæãç«ã£ã¦ããªãã£ããã«ã©ã åããªãã£ãããã¦ããåç
§ããä¸ã§æ¯éããªãéãã¯è¨±å®¹ããããã«ã§ãã¦ããããã®ãã(å±æ§åã¯é¢ä¿ãã¼ã¿ã®å¿
é æ§æè¦ç´ ã®ã¯ããªã®ã§)SQLã§ã¯ãé¢ä¿æ¼ç®ã®çµæã¨ãã¦é¢ä¿ã§ã¯ãªããã¼ã¿ãçããå ´åããã(é¢ä¿æ¼ç®ã®éå
æ§ãæãç«ã£ã¦ããªã)ã
ã¾ãSQLã®ãããªãã¼ãã«åãã«ã©ã åã®æ±ãã¯ãå¤æ°ã¨ç¸æ§ãæªãããã«æããããããSQLã«å¤æ°ã追å ããã¨ãããã
x = person select x.name, person.age charactor.age from x, charactor where x.name = charactor.cast;
ã¨æ¸ãã¦ããã®ãã©ãã(ãã¼ãã«åã®ä¿®é£¾ã¯ã©ã®ç¯å²ã§æå¹ã¨ãªãã®ã)ã
ããããSQLã®ç¹å¾´ã¯ãæ°ãããã¼ã¿ãã¼ã¹è¨èªãä½ããã¨ããã¨ãã®é害ã«ãªããæ°ããè¨èªãåãªãèå³ããã ãã§ãªãããç¨åº¦ã®å®ç¨ãèãã¦ä½ãå ´åãã¾ãã¯SQLã¸ã®ãã©ã³ã¹ã¬ã¼ã¿ãæ¸ãã¦ä½¿ã£ã¦ã¿ãã¨ããã®ããã¶ãç¾å®çãªããæ¹ã«ãªãã
ããããã¨ãã¼ã¿æ§é ä¸ã®é¦å°¾ä¸è²«æ§ãæ±ãããå¤æ°ãå°å
¥ããããã¦æ®éã®ããã°ã©ãã³ã°è¨èªã«è¿ã¥ãããã¨ããã°ããã»ã©SQLã¨ã®ä¹é¢ã大ãããªã£ã¦ããã©ã³ã¹ã¬ã¼ã¿ãæ¸ãã«ãããªããéã«åãããSQLã¸ã®å¤æã念é ã«ããã¦è¨èªè¨è¨ããã¦ãã¾ãã¨ãSQLã®ææ³ãæ©è½ãå¼ããã£ãä¸éå端ãªè¨èªã«ãªã£ã¦ãã¾ã(Schemeã§ãã¯ãã使ã£ã¦å®ç¾ãããSchemeQLããã®ä¾ã ã¨æã)ã
追è¨:é¢é£æç®
- Rel: An Implementation of Date and Darwen's Tutorial D database language
- Daan Leijen and Erik Meijer. Domain specific embedded compilers
- Alexandra Martins da Silva. Strong Types for Relational Data Stored in Databases or Spreadsheets
å¼ã®ä¸ã®å±æ§åã®æ±ã
Tutorial Dã¨SQLã®ã©ã¡ãã«ãå
±éããä½ã¨ãªãæ°æã¡æªãæ§æã¨ãã¦ãè¨ç®å¼ã®ä¸ã§ã®å±æ§å(ã«ã©ã å)ã®ä½¿ãæ¹ãããã
Tutorial D
(person where age > 20){name}
select name from person where age > 20;
ããã§ã®ageã¯æ®éã®ããã°ã©ãã³ã°è¨èªã§ã®å¤æ°ã®ããã«ä½¿ããã¦ãããã©ããã®ageã¯ç¹å®ã®å¤ãæãã¦ããã®ã§ã¯ãªããåè¡ã®ageã«ã©ã ãæå®ãã¦ããããã®ç¹ã§ã¯å¤æ°ã¨ããããæ§é ä½ããªãã¸ã§ã¯ãã®ã¡ã³ãåã«è¿ãããã©ãããã¨ããºã¬ã¦ãã¦ä½ãæ°æã¡æªãæãã(Rubyã§selfãçç¥ãããå ´åãããããè¿ããããããªããåè¡ã®å¦çæ¯ã«selfã¾ãã¯ageã®å¤ãå¤ãããã¨ãããããª)ã
ãã®æ°æã¡æªãã¯ã«ã©ã åããã¼ãã«åã§ä¿®é£¾ãããã®ã«ãæããã
SQL
select name from person where person.age > 20;
ããã¯ä¸è¦ãæ§é ä½ã®ã¡ã³ãæå®ã«ä¼¼ã¦ãããã©ãããã¨ã¯éããããã§ã®ãperson.ageãã¯ãpersonãã¼ãã«ã®ageã«ã©ã ã®å¤ããæãã¦ããã®ã§ã¯ãªãããpersonãã¼ãã«ã®åè¡ã®ageã«ã©ã ã®å¤ãã表ãã¦ããã
ããããéè¨é¢æ°ã§ã®å±æ§åã»ã«ã©ã åã®ä½¿ãæ¹ã«ãåæ§ã®éåæãããã
Tutorial D
summarize person add(avg(age) as avg_age)
select avg(age) from person;
ãããã¯ãLINQã®ããã«å¤æ°ã«ã¿ãã«(è¡)ãä»£å ¥ããä¸ã§åç §ããã¨ããã®ãèªç¶ãªæããããã
from p in person where p.age > 20 select p.name;
person.Where(p => p.age > 20) .Select(p => p.name);
person.Average(p => p.age);
(éè¨é¢æ°ã«ã¤ãã¦ã¯ãéè¨é¢æ°ãå¼æ°ã§æ¸¡ãæ¹ããã£ã¨å¥½ã¿ãã)
ã§ãããã®ãããªææ³ãæ¡ç¨ãã¦ããSQLã¸ã®ãã©ã³ã¹ã¬ã¼ã¿ãæ¸ãã¨ãã¶ããã¤ãºã«ãããªããªãã
æ¬é¡
æ¬é¡ã¯ãSQL以å¤ã®é¢ä¿ãã¼ã¿ãã¼ã¹è¨èªãåºã¦ããªãçç±ãèãããã ã£ããã©ãèããã®ãããã©ãã«ãªã£ãã®ã§å°»åãã¨ãã¼ã§çµããã
ããã¼ã¿ãã¼ã¹å®è·µè¬ç¾©ããèªã¿è¿ããæ¹ããããããããªãããããããã¼ã¿ãã¼ã¹ã·ã¹ãã æ¦è«ããã¡ããã¨èªãã¨ãã
- ä½è : C.J.Date,æ ªå¼ä¼ç¤¾ã¯ã¤ã¼ã
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã¸ã£ãã³
- çºå£²æ¥: 2006/02/01
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 4人 ã¯ãªãã¯: 170å
- ãã®ååãå«ãããã° (56件) ãè¦ã
ãã¼ã¿ãã¼ã¹ã·ã¹ãã æ¦è«
- ä½è : C.J.Date,è¤åè²
- åºç社/ã¡ã¼ã«ã¼: 丸å
- çºå£²æ¥: 1997/03
- ã¡ãã£ã¢: åè¡æ¬
- ã¯ãªãã¯: 155å
- ãã®ååãå«ãããã° (22件) ãè¦ã