代码之家  ›  专栏  ›  技术社区  ›  Community wiki

SQL语法新手

  •  2
  • Community wiki  · 技术社区  · 1 年前

    描述以下SQL查询的输出:

    select custId, name
    from customer
    where region = "New York"
    UNION 
    select cust.custId, cust.name
    from customer cust
    where cust.custId IN (select cust_order.custId
    from customer_order cust_order, company_employee comp_emp
    where cust_order.salesEmpId = comp_emp.empId
    AND comp_emp.name = 'DANIEL');
    

    我的问题是:在包含 from customer cust “cust”是指customer表中的一列吗?

    这是一个家庭作业问题,我已经确定了导致这一行的组成部分 我认为cust是客户表中的一列。。。 如果我走在正确的轨道上,我并不是要求一个整体的解决方案,只是一点鼓励。。。

    8 回复  |  直到 14 年前
        1
  •  5
  •   Chris    14 年前

    cust 是Customer表的别名。所以与其写作 customer.custId ,你可以写 cust.custId

        2
  •  1
  •   Adriaan Stander    14 年前

    您应该了解一下Sql Server TABLE ALIASING

    仔细看看 SELECT Clause (Transact-SQL) 和搜索 别名

        3
  •  1
  •   HLGEM    14 年前

    Cust是客户表上的一个别名。它用于使您不必到处拼写整个表名。

        4
  •  1
  •   symcbean    14 年前

    否-正在为表创建别名

    • 所以每次打字的次数更少
    • 以及处理希望在同一查询中使用表的多个“副本”的情况。
        5
  •  1
  •   Hans Olsson    14 年前

    cust是客户的一个别名,以缩短键入和读取时间。

        6
  •  1
  •   Stephen P    14 年前

    “cust”只是“customer”表名的别名。它允许您写“cust.name”而不是“customer.name”

        7
  •  1
  •   David    14 年前

    cust是customer表的别名。

    由于出于查询的目的,查询将一个表视为两个独立的表(或至少是结果集),因此DB可以知道,当您将“Customers”作为表名时,您指的是来自纽约的表,而“Cust”指的是销售员工名为Daniel的表。

    别名描述如下: http://www.w3schools.com/sql/sql_alias.asp

        8
  •  0
  •   Choudhury Saadmaan Mahmid    10 年前

    “cust”用作“customer”表的别名。