我正在尝试列出所有13岁以上并下载了“社交”类别中的应用的用户。用户的出生日期按升序排列。
我无法理解联接的问题以及如何在SQL中将这些表联接在一起。
下面的代码:
SELECT DISTINCT
u."UserId",
CAST(u."Username" AS varchar2(20)) AS "Username",
CAST(u."FirstName" AS varchar2(15)) AS "FirstName",
CAST(u."LastName" AS varchar2(15)) AS "LastName",
CAST(u."Email" AS varchar2(30)) AS "Email",
u."Gender",
u."JoinDate",
TRUNC(u."DateOfBirth") AS "DateOfBirth",
u."CountryId"
FROM BR_USER u JOIN BR_APPUSER ap ON u."UserId" = ap."UserId", BR_APPUSER ap JOIN BR_APPCATEGORY ac ON ap."AppId" = ac."AppId"
WHERE months_between(TRUNC(sysdate), u."DateOfBirth") / 12 > 13 AND ac."CategoryName" = 'Social'
ORDER BY "DateOfBirth" ASC;
我的加入:
FROM
BR_USER u JOIN BR_APPUSER ap ON u."UserId" = ap."UserId",
BR_APPUSER ap JOIN BR_APPCATEGORY ac ON ap."AppId" = ac."AppId"
答案 0 :(得分:1)
根据您发布的实体关系(ER)图,您需要连接四个表,即User
,AppUser
,App
和AppCategory
。
select U.username
from
User U
inner join
AppUser AU
on
U.userid = AU.userid
inner join
APP A
on
AU.appid = A.appid
inner join
AppCategory AC
on
AC.appCategoryId = A.appCategoryId
where
AC.categoryName = 'Social'