RDBMSã使ã以ä¸ãSQLã使ãããªããªããã°ãããªã
ãä½åº¦ãä½åº¦ãè¨ã£ã¦ãããã©ããå¦çãåå²ããæ¹ãDBãµã¼ãã®è² è·ãæ¸ããã¨æããã®ã¯åéãã
http://d.hatena.ne.jp/Sikushima/20110809/
http://d.hatena.ne.jp/Sikushima/20110810/
http://d.hatena.ne.jp/Sikushima/20110811/
http://d.hatena.ne.jp/Sikushima/20110815/
è½ã¡ãã®ã¯ãã¼ã¯ãããªã
ãhttp://d.hatena.ne.jp/Sikushima/20110815/ ã«ããéããSQLã§DBãµã¼ãã§ã§ãããã¨ãAPãµã¼ãã§è¡ã£ã¦ãDBãµã¼ãã®å
¨ä½ã®å¦çã¯æ¸ããªã訳ã§ãã
ããµã¼ãã«æããè² è·ã¨ããã®ã¯ãã¼ã¯ã§ã¯ãªãé¢ç©ã§è¦ãªããã°ãããªãããã©ãå¦çãæ¸ããªã以ä¸ãDBãµã¼ãã®1åã®å¦çã®é¢ç©ã¯åå²ããæ¹ã大ãããªãã
ããã®ç¶æ ã§ã¢ã¯ã»ã¹ã輻輳ããã°ä¸ã®ããã«ãªãã
ãSQLã®å¦çãé¿ããã°ãDBãµã¼ãã®è² è·ã¯é«ããªãããã§ãã
ããã£ã¨éè¦ãªãã¨ã¯ãSQLã§å¦çãè¡ã£ãã¨ãã®APãµã¼ãã®è² è·ã«æ¯ã¹ãSQLãé¿ãã¦å¦çããã¨ãã®APãµã¼ãã®è² è·ã¯ä½åãé«ããªãã¾ãã
ãã§ããããAPãµã¼ããè¤æ°ãã£ãã¨ãã¦ãããã³ã¯ããã®ã¯å¤§æµAPãµã¼ãã®æ¹ã§ããããããã§ãããããDBãµã¼ãã§å¦çãã¦ããâ¦â¦ãã£ã¦è¨ã訳ãã¦ãå ´é¢ãä½åº¦ãè¦ã¦ãã¾ããã
ãã¨ããããæ¬æ¥ã¯DBãµã¼ãã§å¦çãã¦ããããAPãµã¼ãããã³ã¯ããææãéåãºã©ãã¦ã訳ã§ããï¼ãã¡ãããWebãµã¼ãã®ãã³ã¯ã¯ã©ãã«ãåºæ¥ãªããã©ãï¼
ããããã³ã¯ããAPãµã¼ãããã³ã¯ãããªãããã«ããã¬ã¹ãã³ã¹ãæ©ãããããã«ããDBãµã¼ãã®ãã³ã¯ãé²ãããã«ããSQLã使ã£ãæ¹ãè¯ãããã§ããããä½åº¦ãè¨ã£ã¦ããã©ãSQLãé¿ãã¦å¾ããããã®ã¯ããä¸æããã«åããããã¨ãã§ãããã®ä¸ç¹ãããªãã®ã§ãã
APãµã¼ãã§è¡ã£ãæ¹ãããå¦çããã
ãã¨ã¯ããããã¡ããä¾å¤ã¯åå¨ããã
ãä¾ãã°これã¨ããå ã ãã¡ã¢ãªã¼ä¸ã§å¦çãå®çµãããããªã¢ãããããããDBãµã¼ãã使ãå¿ è¦ããªãã®ã¯å½ããåã
ãããä¸ã¤ããã¿ã¼ã³ããã£ã¦ãååã®åå¼·ä¼ã§åºãåé¡ã
ã¨ãããã¼ãã«ããã以ä¸ã®æ§ã«ä¸çªå¤ãé£åã¨é£æã®æ°ãåºåããã
ãä½ã¨ãªãã§ããããªæ°ã¯ãããã ããã©ãä¸æ©èãã¦ï¼ã¨ãã£ã¦ãå¾¹å¤ããããã§ã¯ãªã夢ã®ä¸ã§æ´çãããã§ããâ¦â¦ï¼ãã£ã±ãçããåºãªãã£ãã
ãåå¼·ä¼ã§åºãçãã¯ããã
SELECT åæå¤, max(cnt) FROM (SELECT åæå¤, count(*) AS cnt FROM (SELECT åæå¤, row_number() OVER (ORDER BY æ¥ä») - row_number() OVER (PARTITION BY åæå¤ ORDER BY æ¥ä») AS cnt FROM 試åçµæ AS s) AS a GROUP BY åæå¤, cnt) AS a GROUP BY åæå¤ ORDER BY åæå¤;
ãã¾ããæ£ããã®ã§ããå¿ç¨ã¯å¹ããªãããã©ãèãã¦ãAPãµã¼ãã§ãã£ãæ¹ãå¹ççã
ãå帰SQLã§ãããã¡ãã¯ããã«æãã¤ããããã©ãå é¨çã«ã¬ã³ã¼ãæ°åSQLãçºè¡ããã¨ããã¨ãã§ããªãSQLã§ããã¡ãããç§ã¨ãã¦ã¯çãã¨ã¯èªããããªãã
WITH m(ID, æ¥ä», åæå¤) AS( SELECT ROW_NUMBER()OVER(ORDER BY æ¥ä»), æ¥ä», åæå¤ FROM 試åçµæ ) , cte(ID ,éå§æ¥ä», æ¥ä», åæå¤, é£åæ°, é£ææ°) AS( SELECT ID , æ¥ä» AS éå§æ¥ä» , æ¥ä» , åæå¤ , CASE WHEN åæå¤ = 1 THEN 1 ELSE 0 END AS é£åæ° , CASE WHEN åæå¤ = 0 THEN 1 ELSE 0 END AS é£ææ° FROM m WHERE ID = 1 UNION ALL SELECT m.ID , CASE WHEN cte.åæå¤ = m.åæå¤ THEN cte.éå§æ¥ä» ELSE m.æ¥ä» END AS éå§æ¥ä» , m.æ¥ä» , m.åæå¤ , CASE WHEN m.åæå¤ = 1 THEN cte.é£åæ° + 1 ELSE 0 END AS é£åæ° , CASE WHEN cte.åæå¤ = 0 THEN cte.é£ææ° + 1 ELSE 0 END AS é£ææ° FROM m INNER JOIN cte ON m.ID = cte.ID + 1 ) SELECT * FROM cte; -- å¾ã¯å¥½ãã«ãµããªã¼ãåã
ãè¦ããã« RDBMS ã¯ã·ã¼ã±ã³ã·ã£ã«ã«ãã¼ã¿ãä¿ããªããã¨ããèããããã·ã¼ã±ã³ã·ã£ã«ãªå¦çãé常ã«è¦æã«ãã¦ããã
ãããã# åæé¢æ°ã§LAGãªã©ã使ãã°ã§ãããã©SQLServerã¯æªå®è£
ãªã®ã§â¦â¦ã
ããã®ãããªå¦çã¯ãå¿ è¦ãªãã¼ã¿ã転éãã¦ç´ ç´ã«APãµã¼ãã§ããããã¹ãã¢ãããã·ã¼ã¸ã£ãçµãã æ¹ãããããã
ãä½ã§ãä¾å¤ã¯ããããã©ãããã¯ããã¾ã§ä¾å¤ã§ãã£ã¦åºæ¬ã¯ç解ããã¹ãã
ææ¥ãåå¼·ä¼ã®å¸ã空ãã¦ã¾ãï¼
ãã¾ããä½ãè¨ãããã£ããã¨ããã¨å®£ä¼ã
ãææ¥ãåå¼·ä¼ã®å¸ã空ãã¦ãã¾ãã®ã§ããæéãããæ¹ã¯ããã£ããã£ã¦ãã ããã
http://sqlworld.org/event/20130827/
SQLWorldâ
大éª#16 éå¬æ
å ±
ãæ¥æã
2013å¹´8æ27æ¥ï¼ç«ææ¥ï¼ã19:00~21:00
ãã¤ãã³ãæ¦è¦ã
SQLWorld 3åç®ã®å¹³æ¥å¤éå¬ããä»åããã¿ããªã§ SQL ãæ¸ãã¦ã¿ããã¨ãããã³ãºãªã³ä¼ç»ã§ãï¼ãã©ã¦ã¶ãããã°åå åºæ¥ãããã«ãã¦ãã¾ãã®ã§ãiPad çã®ã¿ãã¬ããã§ã大ä¸å¤«ã§ãã
ãä¼å ´ã
ãã§ã³ãªã«æ ªå¼ä¼ç¤¾ãã¾å¤§éªæ¬ç¤¾ http://www.fenrir-inc.com/
ã530-0001 大éªåºå¤§éªå¸ååºæ¢
ç° 2-4-9 ããªã¼ã¼ã¿ã¯ã¼ 12F
http://info.fenrir-inc.com/jp/profile/overview.html
JR大éªé§
ãJRåæ°å°é§
ãå°ä¸éæ¢
ç°é§
ã»æ±æ¢
ç°é§
ã»è¥¿æ¢
ç°é§
ã¨åé§
ããã¢ã¯ã»ã¹å¯è½ã§ã
ãåå è²»ã
ç¡æ
ãæã¡ç©ã
ãã½ã³ã³/ã¿ãã¬ãã (DB ã®ã¤ã³ã¹ãã¼ã«ã¯ä¸è¦ã§ãã)
ãåå å¯è½äººæ°ã
13 人
ãTwitterããã·ã¥ã¿ã°ã
#sqlworld