没有主键,有什么方法可以计算差异表中的coluum [英] Is there any ways to count coluum from the difference table without primary key

查看:51
本文介绍了没有主键,有什么方法可以计算差异表中的coluum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2张桌子,活动和志愿者

在活动表中包含

Activity_ID(PK)
Activity_Name
Activity_StartDate(数据类型日期)
Activity_EndDate(数据类型日期)

和志愿者表由
组成
V_ID(PK)
V_Name
V_StartWorking(数据类型日期)

我只想知道每个志愿者开始后进行了多少活动工作
我已经尝试过功能CROSS JOIN,但是没有用.因此,您对我有什么建议吗?

非常感谢

I have the 2 tables ,Activity and Volunteer

In Activity Table consist of

Activity_ID (PK)
Activity_Name
Activity_StartDate (DataType Date)
Activity_EndDate (DataType Date)

and Volunteer Table consist of

V_ID(PK)
V_Name
V_StartWorking (DataType Date)

I just want to know how many activity was hold after each volunteer startWorking
I have tried Function CROSS JOIN but it did not work. Thus do you have any suggestions for me?

Thanks so much

推荐答案

您尚未为志愿者分配活动
因此,您不能关联表

您应该具有如下数据库结构
例如.
tblActivity
you haven''t assigned Activity to volunteer
so, that you can not relate tables

you should have database structure like below
eg.
tblActivity
Activity_ID (PK)
Activity_Name
Activity_StartDate (DataType Date)
Activity_EndDate (DataType Date)



tblvolunteer



tblvolunteer

V_ID(PK)
V_Name



tblRelate



tblRelate

V_ID(FK)
Activity_ID(FK)
V_StartWorking (DataType Date)



现在,使用inner-join或left-join



now, use inner-join or left-join

select Activity_ID,Activity_Name ,Activity_StartDate , Activity_EndDate,V_ID,V_Name,V_StartWorking
from tblrelate r
left join tblActivity a on a.Activity_ID=r.Activity_ID
left join tblvolunteer v on v.V_ID=r.V_ID


祝您编码愉快!
:)


Happy Coding!
:)


我认为您需要检索每个志愿者开始工作后举行的活动的数量.

I think you need to retrieve number of activities held after each volunteer started their work.

select a.* from activity a,volunteer v where a.Activity_StartDate>=v.V_StartWorking




但这会给您重复的记录.
因此,我建议您在这两个表之间有一个映射列或映射表




But this will give you repeated records.
So i will advise you to have a mapping column or mapping table between these two tables


这篇关于没有主键,有什么方法可以计算差异表中的coluum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆