-1

我正在尝试根据业务和订阅者 ID 获取成员。但这不能正常工作。请帮我解决这个问题。

SELECT distinct m.Fname,m.Created,m.[User_Name],b.Business_Name 
FROM dbo.Members m,dbo.Business b,dbo.Assign_Business a 
WHERE  m.Subcriber_id=a.Subscriber_id 
AND  a.Business_id=b.id 
AND b.Subcriber_id=a.Subscriber_id 
AND  a.Business_id='6' AND a.Subscriber_id='1'
4

4 回答 4

1

没有看到你的表的 DDL 很难说,但你可以试试

SELECT DISTINCT 
       m.Fname,m.Created,m.[User_Name],b.Business_Name 
  FROM dbo.Business b INNER JOIN 
       dbo.Assign_Business a ON a.Business_id=b.id AND 
                                a.Subscriber_id=b.Subcriber_id INNER JOIN
       dbo.Members m ON m.Subcriber_id=a.Subscriber_id
 WHERE a.Business_id=6 AND 
       a.Subscriber_id=1
于 2013-02-14T06:04:11.933 回答
1

尝试以下操作:

SELECT DISTINCT
   m.Fname,
   m.Created,
   m.[User_Name],
   b.Business_Name 
FROM dbo.Members m
   INNER JOIN dbo.Assign_Business a ON m.Subcriber_id=a.Subscriber_id
   INNER JOIN dbo.Business b ON a.Business_id=b.id AND b.Subcriber_id=a.Subscriber_id 
WHERE  
   a.Business_id='6' AND a.Subscriber_id='1'
于 2013-02-14T06:05:05.243 回答
1

尝试这个..

select distinct m.Fname,m.Created,m.[User_Name],b.Business_Name 
from dbo.Members m
left join dbo.Assign_Business a on m.Subcriber_id=a.Subscriber_id
left join dbo.Business b on a.Business_id=b.id 
 where a.Business_id='6' and a.Subscriber_id='1' and  b.Subcriber_id=a.Subscriber_id 
于 2013-02-14T06:00:45.213 回答
1

第一步,干净地格式化你的代码。这对调试有很大帮助。

SELECT 
  distinct m.Fname,
           m.Created,
           m.[User_Name],
           b.Business_Name 
FROM 
  dbo.Members as M 
  inner join dbo.Assign_Business as A on M.Subscriber_Id = A.Subscriber_id
  inner join dbo.Business as B on B.id = A.Business_id and B.Subscriber_id = A.Subscriber_id 
WHERE
  A.Business_ID = '6'
  and A.Subscriber_id = '1'
于 2013-02-14T06:01:40.933 回答