Counting substrings in a string
问题 How can I count the numbers of times a substring shows up in a string? In this case, I'm looking for every time " connect.facebook.net/en_US/all.js " shows up in the HTML bodies of the top 300K internet sites (stored in httparchive). 回答1: You could use SPLIT() on the string, and count the number of records produced: SELECT fb_times, COUNT(*) n_pages FROM (SELECT COUNT(splits)-1 WITHIN RECORD AS fb_times FROM (SELECT SPLIT(body, 'connect.facebook.net/en_US/all.js') splits FROM [httparchive