我是SQL Queries的新手。我想获得这些数据:
表1:
表2:
表1数据 TABLE 1 DATA
表2数据 TABLE 2 DATA
TABLE 1
USER_FIRST_NAME
USER_LAST_NAME
TABLE 2
ACTIVITY_NAME
ACTIVITY_DATE
ACTIVITY_TIME
我想获得我正在处理的人的活动。或换句话说
WHERE USER_SUPERVISOR = USER_ID和USER_FULL_NAME = COORD_NAME。
当我使用此代码时,我的代码如下所示:
SELECT USER_LAST_NAME,
USER_FIRST_NAME,
ACTIVITY_NAME,
ACTIVITY_DATE,
ACTIVITY_TIME
FROM user_hierarchy
JOIN ret_activities_at_outlet
ON user_hierarchy.USER_FULL_NAME = ret_activities_at_outlet.COORD_NAME
WHERE user_hierarchy.USER_SUPERVISOR = "1"
答案 0 :(得分:0)
假设一个人有很多活动
SELECT USER_LAST_NAME,
USER_FIRST_NAME,
ACTIVITY_NAME,
ACTIVITY_DATE,
ACTIVITY_TIME
FROM user_hierarchy
RIGHT JOIN ret_activities_at_outlet
ON user_hierarchy.USER_FULL_NAME = ret_activities_at_outlet.COORD_NAME
WHERE user_hierarchy.USER_SUPERVISOR = "1"
enter code here
或许多人有很多活动
SELECT USER_LAST_NAME,
USER_FIRST_NAME,
ACTIVITY_NAME,
ACTIVITY_DATE,
ACTIVITY_TIME
ret_activities_at_outlet left join user_hierarchy
ON user_hierarchy.USER_FULL_NAME = ret_activities_at_outlet.COORD_NAME
WHERE user_hierarchy.USER_SUPERVISOR = "1"