求助 2张表联合查询的语句怎么写?
我准备做一个客户关系的系统,可是被最后的查询难住了,望各位达人指点
存在2张表,一张联系人,一张工作日志
具体如下
表及数据如下如下
---创建表联系人
CREATE TABLE [contact] (
[CID] [int] IDENTITY (1, 1) NOT NULL ,
[create_man] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[account] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[contact] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[share_man] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[create_date] [datetime] NULL ,
CONSTRAINT [PK_contact] PRIMARY KEY CLUSTERED
(
[CID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
---创建表工作日志
CREATE TABLE [action] (
[AID] [int] IDENTITY (1, 1) NOT NULL ,
[action_man] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[account] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[contact] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[action_content] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[acction_date] [datetime] NULL ,
CONSTRAINT [PK_action] PRIMARY KEY CLUSTERED
(
[AID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
---插入联系人
insert into contact values ('人员A','公司A','张三','业务员A','2012-12-20')
insert into contact values ('人员B','公司B','王二','业务员B','2012-12-21')
insert into contact values ('人员A','公司A','李四','业务员D','2012-12-22')
insert into contact values ('人员D','公司B','张三','业务员A','2012-12-23')
insert into contact values ('人员C','公司C','赵大','业务员C','2012-12-24')
---插入工作日志
insert into action values ('业务员A','公司B','张三','电话联系','2013-01-01')
insert into action values ('业务员B','公司B','王二','拜访','2013-01-02')
insert into action values ('业务员B','公司B','王二','第二次拜访','2013-01-03')
insert into action values ('业务员A','公司A','张三','拜访','2013-01-04')