I have a huge table containing 161 million rows. The table structure is entryid(varchar), dater(date), region(char), detail(varchar), views(int), and the first four columns are together as the primary key. I want to do the following processing:
-
detailincludes URL such aswww.google.com,www.google.ca,www.google.uk,www.facebook.com,facebook.com, etc. I want to group those rows from the same domain, for example, usingLIKE "%.google.%"forgoogleandLIKE "%.facebook.%" OR LIKE "facebook.%"forfacebookare good enough. But if update the rows, there might be duplicate key, how to useON DUPLICATE KEY UPDATEto sum theviews? And is there a faster way other thanLIKE? -
I want to remove the
regioncolumn and group the rows and sum theviewsand insert into a new table. How to do that in one command? -
I want to group the rows (and update the
views) by month.
Try this, for MYSQL, assuming that for every row, the detail field looks like http://www.something.com.
Or you could use a subquery to make it look a bit cleaner: