日期:2014-05-16 浏览次数:20608 次
use tempdb;
go
IF OBJECT_ID('dbo.users','U') IS NOT NULL DROP TABLE dbo.users;
IF OBJECT_ID('dbo.users_money','U') IS NOT NULL DROP TABLE dbo.users_money;
--创建人员信息表
CREATE TABLE users (id INT NOT NULL,name varchar(50) NOT NULL,manager INT );
?
INSERT INTO users VALUES
(1,'张三',0),(2,'李四',1),(3,'赵二',1),(4,'王五',2),(5,'陈六',2)
?
?
----创建费用表
CREATE TABLE users_money([userid] INT,[date] date,[money] INT);
?
INSERT INTO users_money VALUES
(1,GETDATE(),FLOOR(RAND()*100)),
(1,DATEADD(DAY,1,GETDATE()),FLOOR(RAND()*100)),
(1,DATEADD(DAY,2,GETDATE()),FLOOR(RAND()*100)),
(1,DATEADD(DAY,3,GETDATE()),FLOOR(RAND()*100)),
(1,DATEADD(DAY,4,GETDATE()),FLOOR(RAND()*100)),
(1,DATEADD(DAY,5,GETDATE()),FLOOR(RAND()*100)),
(1,DATEADD(DAY,6,GETDATE()),FLOOR(RAND()*100)),
(2,GETDATE(),FLOOR(RAND()*100)),
(2,DATEADD(DAY,1,GETDATE()),FLOOR(RAND()*100)),
(2,DATEADD(DAY,2,GETDATE()),FLOOR(RAND()*100)),
(2,DATEADD(DAY,3,GETDATE()),FLOOR(RAND()*100)),
(2,DATEADD(DAY,4,GETDATE()),FLOOR(RAND()*100)),
(2,DATEADD(DAY,5,GETDATE()),FLOOR(RAND()*100)),
(2,DATEADD(DAY,6,GETDATE()),FLOOR(RAND()*100)),
(3,GETDATE(),FLOOR(RAND()*100)),
(3,DATEADD(DAY,1,GETDATE()),FLOOR(RAND()*100)),
(3,DATEADD(DAY,2,GETDATE()),FLOOR(RAND()*100)),
(3,DATEADD(DAY,3,GETDATE()),FLOOR(RAND()*100)),
(3,DATEADD(DAY,4,GETDATE()),FLOOR(RAND()*100)),
(3,DATEADD(DAY,5,GETDATE()),FLOOR(RAND()*100)),
(3,DATEADD(DAY,6,GETDATE()),FLOOR(RAND()*100)),
(4,GET