0

我有两个单独的查询。

1)

SELECT Email, UserId, FirstName, LastName FROM user WHERE 1;

2)

      SELECT COUNT(PostId) as userTextCount
        FROM posts 
  INNER JOIN user ON user.UserID =  posts.PostedAsId
       WHERE UserId='$uid'
         AND PostedAs='USER'
         AND PostType='text';

我想将这两个查询合二为一。问题是在第二个查询中有一个名为 $uid 的变量,我将在运行第一个查询后得到它。我们能否以不需要该变量并结合这两个查询的方式进行操作。如果您需要更多说明,请告诉我。

谢谢。

4

1 回答 1

1
SELECT Email, UserID, FirstName, LastName, count(*) as userTextCount
FROM user INNER JOIN posts ON posts.PostedAsId = user.UserID and PostedAs = 'USER'
  and PostType = 'text'
WHERE 1
GROUP BY Email, UserID, FirstName, LastName
于 2013-11-01T14:58:48.743 回答