您好我有以下数据库结构:
表users
包含:email, name
表connections
包含:followingemail, followedemail, isfollowedaccept
表locations
包含:location, email
。
我希望在以下情况下获得我朋友的name
和location
:我的电子邮件的价值是followingemail
而且我的价值是我朋友的电子邮件是followedemail
。
只有当connctions
表格中有一行包含我的电子邮件为followingemail
且我朋友的电子邮件为followedemail
且isfollowedaccept
为真时,它才会检索数据
我的问题是如何编写该查询?
我无法理解。感谢。
答案 0 :(得分:0)
试试这个:
select u.name, l.location
from connections C
join users U on U.followedemail = C.email
join location l on l.email = C.email
where C.followingemail = (your email)
and U.followedemail = (your friend's email)
and U.isfollowedaccept = true
答案 1 :(得分:0)
您需要加入locations
和select
u1.name as following_name,
u2.name as followed_name,
l1.location as following_location,
l2.location as followed_location
from connections c
join users u1 on u1.email = c.followingemail
join users u2 on u2.email = c.followedemail
join locations l1 on l1.email = c.followingemail
join locations l2 on l2.email = c.followedemail
where
c.followingemail = '{your email}'
and c.followedemail = '{friends email}'
and c. isfollowedaccept = 'true'
两次以获取数据,例如
getListView().smoothScrollToPositionFromTop(position,offset,duration);