æè¿Webã®ã³ã³ã½ã¼ã«ã§ã¯ã¨ãªãæ¸ãã¨ãã«æ°ãã¤ãããããªã¨æã£ããã¨ãã¡ã¢ãã¦ãã
- ã¯ã¨ãªã«Standard SQLã使ã£ã¦ãããLegacy SQLã使ã£ã¦ããããæè¨ãã
- ãã©ã¡ã¼ã¿ã®å®æ°ã¯ã§ããã ãããããããã¾ã¨ãã¦ãã
- ä½ãããã¯ã¨ãªãæåã«ã³ã¡ã³ããæ¸ãã¦ãã
- WITHå¥ã使ã£ã¦ã§ããã ãå ±éé¨åãã¾ã¨ãã¦ãã
ã¯ã¨ãªã«Standard SQLã使ã£ã¦ãããLegacy SQLã使ã£ã¦ããããæè¨ãã
ã¯ã¨ãªã®1è¡ç®ã«#standardSQL
ã#legacySQL
ãªã©ã¨æ¸ããã¨ã§ã©ã¡ãã®ç¨®é¡ã®SQLã使ããæå®ã§ãã
ãããæå®ãã¦ãããªãã¨ã³ãããã¦å®è¡ããã¨ããªã©ã«ãéãæ¹ã§åãã¦ã¨ã©ã¼ã«ãªã£ããããã®ã§ã§ããã ãæ¸ãã¦ãã
ãã©ã¡ã¼ã¿ã®å®æ°ã¯ã§ããã ãããããããã¾ã¨ãã¦ãã
ã¯ã¨ãªä¸ã«å«ã¾ããæ¡ä»¶ãªã©ã®å®æ°ã¯å¾ããå¤ããããªã£ãããããã¨ãå¤ããæ®éã«ã¯ã¨ãªä¸ã«æ¸ãã¦ããã¨ã©ããå¤ããã°ãããããããªããªã
ã¾ãåãå®æ°ãè¤æ°åã¯ã¨ãªã«ç»å ´ããã¨ãã«ããããããªãã©ã«ã¨ãã¦æ¸ãã¦ããã¨ä¸æ¬ãã¦ä¿®æ£ããã®ã大å¤ã ã£ããæ¼ããçºçããããã¦ãã¾ãã¾ã
以ä¸ã®è¨äºã§ãæ¸ãããUDFã®é¢æ°ã¨ãã¦å®æ°ãå®ç¾©ãã¦ãã¾ãã¨ãããããã
éãªä¾ãæ¸ãã¨ä»¥ä¸ã®ããã«ãã©ã¡ã¼ã¿ã®å®æ°ãUDFã¨ãã¦å®ç¾©ãã¦ã³ã¡ã³ããæ¸ãã¦ããã¨ãã¨ããè¦ã¦ããããããããã©ããå¤ããã°ãããã¯ä¸ç®çç¶ã ã¨æã
#standardSQL #éè¨ã®éå§æ¥ CREATE TEMPORARY FUNCTION START_DATE() AS ('20170701'); #éè¨ã®çµäºæ¥ CREATE TEMPORARY FUNCTION END_DATE() AS ('20170731'); SELECT * FROM `foo.bar*` WHERE _TABLE_SUFFIX BETWEEN START_DATE() AND END_DATE()
ä½ãããã¯ã¨ãªãæåã«ã³ã¡ã³ããæ¸ãã¦ãã
1è¡ç®ã«Standard SQLãLegacy SQLãæ¸ãã次ã®è¡ã«ã¯ã¨ãªã®èª¬æãæ¸ãã¦ããã¨ããã¨æãã¾ã
説æãæ¸ãã¦ããã¨ã¯ã¨ãªã®å±¥æ´ã®ç»é¢ãè¦ãã¨ãã«ãããããããªãã¾ã
ã¾ãæ¤ç´¢ã§ãæ¢ãããããªãã¾ãããã¨ãã°æ¥ä»ãæ¸ãã¦ããã°æ¥ä»ã§æ¤ç´¢ããããã§ãã¾ã
å¾ããå¿
è¦ãªã¯ã¨ãªã¯ååãã¤ãã¦ä¿åãã¦ããã°ãã話ã§ããã使ãã¾ããäºå®ã®ãªãã¯ã¨ãªãå¾ãã使ããããªã£ãããããã®ã§æ¤ç´¢ãããããªã£ã¦ããã¨ä¾¿å©ã§ã
WITHå¥ã使ã£ã¦ã§ããã ãå ±éé¨åãã¾ã¨ãã¦ãã
å ±éã®å¦çãã¯ã¨ãªä¸ã®è¤æ°ç®æã«ã³ããããã¦ããã¨ä¿®æ£ããã¨ãã«å¤§å¤ã«ãªãã®ã§ã§ããã ãWITHå¥ã使ã£ã¦ã¾ã¨ãã