请用英语解释这个SQL语句!

时间:2011-03-01 09:44:01

标签: sql

SELECT a.*,
       b.*,
       b.id AS user_id,
       a.id AS group_id 
FROM groups a,
     users b 
WHERE a.group_leader_id = b.id

谢谢。

6 个答案:

答案 0 :(得分:1)

SELECT a.*, b.*, b.id //select all columns from a, b and id from table b with alias user_id
AS user_id, a.id     // id from table a with alias group_id
AS group_id 
FROM groups a, users b  //from tables groups and users with aliases a and b
WHERE a.group_leader_id = b.id  //where group_leader_id from groups = id from users.

答案 1 :(得分:1)

此语句是组的组长外键上的两个表组和用户之间的连接。

所以我会这样说: 显示组负责人的用户信息(冗余重命名为user_id和group_id)。

答案 2 :(得分:1)

列出所有团体及其领导人。

SELECT 
    a.*, 
    b.*, 
    b.id AS user_id, 
    a.id AS group_id 
FROM 
    groups a
INNER JOIN 
    users b 
ON 
    a.group_leader_id = b.id

答案 3 :(得分:1)

显示所有群组,仅显示作为群组领导者的用户

SELECT a.*, b.*, 
b.id AS user_id, -- use an alias for users.id
a.id AS group_id -- use an alias for groups.id
FROM groups a, -- alias table groups as 'a'
  users b -- alias table users as 'b'
WHERE a.group_leader_id = b.id -- show only those users who are a leader of a group, and link them to that group

据我所知,您的查询可以针对此进行优化:

SELECT a.*, b.*, b.id AS user_id, a.id AS group_id
FROM groups a 
  INNER JOIN users b ON a.group_leader_id = b.id

答案 4 :(得分:0)

这意味着从2个表中挑选出Group Leaders(没有说明具体细节),其中B有Group Leaders的列表,A有用户的详细信息。

答案 5 :(得分:0)

给我组中的所有列+来自用户的所有列+重命名b.id作为user_id +将a.id重命名为group_id,从组中的所有行中将组与用户匹配。