SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[view_VisitIp]
AS
select * from (select count(ip) as ipcount, '0' as [hour] from (select t .ip, min(t .addtime) as 'addtime' from visit_site t where datediff(day, getdate(), t .addtime) = 0 group by t .ip) as more where datepart(hour, addtime) >= 0 and datepart(hour, addtime) < 1 union all select count(ip) as ip, '1' as [hour] from (select t .ip, min(t .addtime) as 'addtime'
 from visit_site t where datediff(day, getdate(), t .addtime) = 0 group by t .ip) as more
 where datepart(hour, addtime) >= 1 and datepart(hour, addtime) < 2 union all select     count(ip) as ip, '2' as [hour] from (select t .ip, min(t .addtime) as 'addtime' from         visit_site t where datediff(day, getdate(), t .addtime) = 0 group by t .ip) as more where  datepart(hour, addtime) >= 2 and datepart(hour, addtime) < 3 union all select count(ip) as ip, '3' as [hour] from (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 3 and datepart(hour, addtime) < 4
                       union all
                       select     count(ip) as ip, '4' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 4 and datepart(hour, addtime) < 5
                       union all
                       select     count(ip) as ip, '5' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 5 and datepart(hour, addtime) < 6
                       union all
                       select     count(ip) as ip, '6' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 6 and datepart(hour, addtime) < 7
                       union all
                       select     count(ip) as ip, '7' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 7 and datepart(hour, addtime) < 8
                       union all
                       select     count(ip) as ip, '8' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 8 and datepart(hour, addtime) < 9
                       union all
                       select     count(ip) as ip, '9' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 9 and datepart(hour, addtime) < 10
                       union all
                       select     count(ip) as ip, '10' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 10 and datepart(hour, addtime) < 11
                       union all
                       select     count(ip) as ip, '11' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 11 and datepart(hour, addtime) < 12
                       union all
                       select     count(ip) as ip, '12' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 12 and datepart(hour, addtime) < 13
                       union all
                       select     count(ip) as ip, '13' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 13 and datepart(hour, addtime) < 14
                       union all
                       select     count(ip) as ip, '14' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 14 and datepart(hour, addtime) < 15
                       union all
                       select     count(ip) as ip, '15' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 15 and datepart(hour, addtime) < 16
                       union all
                       select     count(ip) as ip, '16' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 16 and datepart(hour, addtime) < 17
                       union all
                       select     count(ip) as ip, '17' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 17 and datepart(hour, addtime) < 18
                       union all
                       select     count(ip) as ip, '18' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 18 and datepart(hour, addtime) < 19
                       union all
                       select     count(ip) as ip, '19' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 19 and datepart(hour, addtime) < 20
                       union all
                       select     count(ip) as ip, '20' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 20 and datepart(hour, addtime) < 21
                       union all
                       select     count(ip) as ip, '21' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 21 and datepart(hour, addtime) < 22
                       union all
                       select     count(ip) as ip, '22' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 22 and datepart(hour, addtime) < 23
                       union all
                       select     count(ip) as ip, '23' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate(), t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 23 and datepart(hour, addtime) < 24) today
union all
select     *
from         (select     count(ip) as ip, '24' as [hour]
                       from          (select     t .ip, min(t .addtime) as 'addtime'
                                               from          visit_site t
                                               where      datediff(day, getdate() - 1, t .addtime) = 0
                                               group by t .ip) as more
                       where      datepart(hour, addtime) >= 0 and datepart(hour, addtime) < 1
                       union all
                       select     count(ip) as ip, '25' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 1 and datepart(hour, addtime) < 2
                       union all
                       select     count(ip) as ip, '26' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 2 and datepart(hour, addtime) < 3
                       union all
                       select     count(ip) as ip, '27' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 3 and datepart(hour, addtime) < 4
                       union all
                       select     count(ip) as ip, '28' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 4 and datepart(hour, addtime) < 5
                       union all
                       select     count(ip) as ip, '29' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 5 and datepart(hour, addtime) < 6
                       union all
                       select     count(ip) as ip, '30' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 6 and datepart(hour, addtime) < 7
                       union all
                       select     count(ip) as ip, '31' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 7 and datepart(hour, addtime) < 8
                       union all
                       select     count(ip) as ip, '32' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 8 and datepart(hour, addtime) < 9
                       union all
                       select     count(ip) as ip, '33' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 9 and datepart(hour, addtime) < 10
                       union all
                       select     count(ip) as ip, '34' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 10 and datepart(hour, addtime) < 11
                       union all
                       select     count(ip) as ip, '35' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 11 and datepart(hour, addtime) < 12
                       union all
                       select     count(ip) as ip, '36' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 12 and datepart(hour, addtime) < 13
                       union all
                       select     count(ip) as ip, '37' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 13 and datepart(hour, addtime) < 14
                       union all
                       select     count(ip) as ip, '38' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 14 and datepart(hour, addtime) < 15
                       union all
                       select     count(ip) as ip, '39' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 15 and datepart(hour, addtime) < 16
                       union all
                       select     count(ip) as ip, '40' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 16 and datepart(hour, addtime) < 17
                       union all
                       select     count(ip) as ip, '41' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 17 and datepart(hour, addtime) < 18
                       union all
                       select     count(ip) as ip, '42' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 18 and datepart(hour, addtime) < 19
                       union all
                       select     count(ip) as ip, '43' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 19 and datepart(hour, addtime) < 20
                       union all
                       select     count(ip) as ip, '44' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 20 and datepart(hour, addtime) < 21
                       union all
                       select     count(ip) as ip, '45' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 21 and datepart(hour, addtime) < 22
                       union all
                       select     count(ip) as ip, '46' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 22 and datepart(hour, addtime) < 23
                       union all
                       select     count(ip) as ip, '47' as [hour]
                       from         (select     t .ip, min(t .addtime) as 'addtime'
                                              from          visit_site t
                                              where      datediff(day, getdate() - 1, t .addtime) = 0
                                              group by t .ip) as more
                       where     datepart(hour, addtime) >= 23 and datepart(hour, addtime) < 24) today
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'view_VisitIp'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'view_VisitIp'
