日期:2014-05-18  浏览次数:20673 次

求一SQL语句,从原始表得到想要的数据!!!!!!!
要求:
以字段SESSION_ID分组做GROUP,获取最小的VISIT_TIME,和最小VISIT_TIME对应的REFERRER,还有如果URL='/login/reg.aspx',就把结果记录中的REGFLG字段置为1。
原始表
VISIT_TIME SESSION_ID URL REFERRER
2011/11/9 9:28 FE6FE647CD8E4D79A7B878A57C954CE9 /login/login.aspx NULL
2011/11/9 9:19 CCFDD3ED891D42F3A03055A975F4A2C1 /Content/418.html http://help.sina.com/payarea.html?page=/Content/21.html
2011/11/9 9:27 CCFDD3ED891D42F3A03055A975F4A2C1 / http://www.baidu.com/s?wd=%B7%B2%BF%CD%B3%CF%C6%B7
2011/11/9 23:42 1752F55AB02C4C79B50E375B3DAEB85E /Login/Login.aspx NULL
2011/11/9 9:37 FE6FE647CD8E4D79A7B878A57C954CE9 /shopping/shopping.aspx http://item.sina.com/0120958.html
2011/11/9 10:00 FE6FE647CD8E4D79A7B878A57C954CE9 /Order/ http://my.sina.com/order/
2011/11/9 9:31 FE6FE647CD8E4D79A7B878A57C954CE9 /Content/38.html http://help.sina.com/payarea.html?page=/Content/21.html
2011/11/9 9:59 FE6FE647CD8E4D79A7B878A57C954CE9 /order/ NULL
2011/11/9 23:47 1752F55AB02C4C79B50E375B3DAEB85E / http://s.sina.com/2776.html
2011/11/9 23:45 1752F55AB02C4C79B50E375B3DAEB85E /0095787.html http://item.sina.com/0067878.html?ref=Search_Browse_1_0067878
2011/11/9 23:42 1752F55AB02C4C79B50E375B3DAEB85E / http://www.baidu.com/s?wd=%B7%B2%BF%CD%B3%CF%C6%B7
2011/11/9 23:56 1752F55AB02C4C79B50E375B3DAEB85E /0159577.html http://fashion.sina.com/search/?navtype=02&cateid=5142
2011/11/9 23:47 1752F55AB02C4C79B50E375B3DAEB85E /channel/men.html http://www.sina.com/
2011/11/9 23:58 1752F55AB02C4C79B50E375B3DAEB85E /0159577.html http://fashion.sina.com/search/?navtype=05&cateid=5142
2011/11/9 9:28 FE6FE647CD8E4D79A7B878A57C954CE9 / NULL
2011/11/9 23:59 1752F55AB02C4C79B50E375B3DAEB85E /search/ http://fashion.sina.com/search/?navtype=05&cateid=5142
2011/11/9 9:29 FE6FE647CD8E4D79A7B878A57C954CE9 /0120958.html http://weiyi.sina.com/
2011/11/9 9:33 FE6FE647CD8E4D79A7B878A57C954CE9 /Content/21.html http://help.sina.com/Content/21.html
2011/11/9 9:32 FE6FE647CD8E4D79A7B878A57C954CE9 /Content/21.html http://help.sina.com/Content/38.html
2011/11/9 9:33 FE6FE647CD8E4D79A7B878A57C954CE9 /Content/21.html http://help.sina.com/Content/21.html
2011/11/9 23:54 1752F55AB02C4C79B50E375B3DAEB85E / http://www.baidu.com/s?wd=%B7%B2%BF%CD%B3%CF%C6%B7
2011/11/9 9:27 CCFDD3ED891D42F3A03055A975F4A2C1 /login/login.aspx NULL
2011/11/9 10:00 FE6FE647CD8E4D79A7B878A57C954CE9 / http://my.sina.com/Order/
2011/11/9 9:24 CCFDD3ED891D42F3A03055A975F4A2C1 /shopping/shopping.aspx http://help.sina.com/Content/418.html
2011/11/9 9:20 CCFDD3ED891D42F3A03055A975F4A2C1 /login/reg.aspx NULL
2011/11/9 23:44 1752F55AB02C4C79B50E375B3DAEB85E /0067878.html http://s.sina.com/2776.html
2011/11/9 23:49 1752F55AB02C4C79B50E375B3DAEB85E /1247.html http://s.sina.com/1247.html
2011/11/9 9:28 FE6FE647CD8E4D79A7B878A57C954CE9 / http://www.sina.com/
2011/11/9 9:58 FE6FE647CD8E4D79A7B878A57C954CE9 /Shopping/Shopping_Complete.aspx https://shopping.sina.com/shoppingcar/index
2011/11/9 9:58 FE6FE647CD8E4D79A7B878A57C954CE9 /Shopping/Shopping_Complete.aspx https://shopping.sina.com/shoppingcar/index
2011/11/9 9:14 CCFDD3ED891D42F3A03055A975F4A2C1 /0120958.html http://weiyi.sina.com/
2011/11/9 9:13 CCFDD3ED891D42F3A03055A975F4A2C1 / http://www.sina.com/?source=bdzqbtd56a1cce0ea3fe76
2011/11/9 23:59 1752F55AB02C4C79B50E375B3DAEB85E / http://fashion.sina.com/search/?navtype=05
2011/11/9 9:13 CCFDD3ED891D42F3A03055A975F4A2C1 / http://www.baidu.com/s?wd=%B7%B2%BF%CD%B3%CF%C6%B7
2011/11/9 23:45 1752F55AB02C4C79B50E375B3DAEB85E /0067878.html http://s.sina.com/2776.html
2011/11/9 9:32 FE6FE647CD8E4D79A7B878A57C954CE9 /Content/21.html http://help.sina.com/Content/38.html
2011/11/9 23:47 1752F55AB02C4C79B50E375B3DAEB85E /1247.html http://www.sina.com/channel/men.html
2011/11/9 9:27 CCFDD3ED891D42F3A03055A9