试图从桌子上拿钱

时间:2011-07-04 10:08:13

标签: mysql sql sql-server

我有

会员表

member_Id
Last name
first name
postcode
reference

另一个表memberstomships

member_Id
membertomship_lastdate
membertomship_paymentmethod  column with values money  
member_id
membershipstatusid
membershipoptionid

另一个表membership membershipstatustype表

membershipstatusid
memberstatustype_name

另一个表membership membership

membershiptype_id
membershiptype_name

另一个表membership membership选项

membershiptype_id
membershipoptionid

我想获得lastname和firstname以及memberstatustype_name和membershiptype_name以及membertomship_lastdate给那些拥有membertomship_paymentmethod就是金钱的会员

任何人都可以帮助我....

非常感谢。

4 个答案:

答案 0 :(得分:4)

自己动手!以下是有关如何使用SQL连接的教程:

http://w3schools.com/sql/sql_join.asp

http://www.tizag.com/sqlTutorial/sqljoin.php

“给一个人一条鱼,你喂他一天。教一个人钓鱼,你养了一辈子。“

答案 1 :(得分:2)

这样的东西?

SELECT 
  member.lastname,
  member.firstname
  membershipstatustype.memberstatustype_name
  membershiptype.membershiptype_name
  memberstomships.membertomship_lastdate
FROM 
  member
  INNER JOIN memberstomships ON member .member_id = memberstomships.memberid
  INNER JOIN membershipstatustype ON memberstomships.membershipstatusid = membershipstatustype.membershipstatusid 
  INNER JOIN membershiptype ON membershipstatustype.membershiptype_name = membershiptype.membershiptype_name 
WHERE
  UCASE(memberstomships.membertomship_paymentmethod) = 'MONEY'

答案 2 :(得分:1)

试试这个,

SELECT  Member.LastName,  Memebr.FirstName, memberstatustype_name, membershiptype_name, membertomship_lastdate,
FROM Members
 LEFT JOIN  Memberstomships
ON Memberstomships.member_Id = Members .member_Id
LEFT JOIN  membershipstatustype
ON membershipstatustype .membershipstatusid = Memberstomships.membershipstatusid 
LEFT JOIN membershipoption 
ON membershipoption .membershipoptionid = memberstomships.membershipoptionid 
LEFT JOIN  membershiptype
ON membershipstatustype .membershiptype_id = membershipoption .membershiptype_id
WHERE membertomship_paymentmethod =  'money'

答案 3 :(得分:0)

如果您使用 LIKE 运算符来比较字符串,那就更好了。

P.S。您的表格和字段名称真的很难读。纠正它们。