首页 > 试题广场 >

50.纠错4 表Customers含有字段cust_name

[单选题]
50.纠错4
表Customers含有字段cust_name顾客名、cust_contact顾客联系方式、cust_state顾客州、cust_email顾客email
cust_name cust_contact
cust_state cust_email
cust10 8695192 MI cust10@cust.com
cust1 8695193
MI cust1@cust.com
cust2
8695194
IL cust2@cust.com
【问题】修正下面错误的SQL
SELECT cust_name, cust_contact, cust_email 
FROM Customers 
WHERE cust_state = 'MI' 
ORDER BY cust_name; 
UNION 
SELECT cust_name, cust_contact, cust_email 
FROM Customers 
WHERE cust_state = 'IL'ORDER BY cust_name;
【示例结果】
返回顾客名称:cust_name、顾客联系方式:cust_contact、顾客email:cust_email
cust_name cust_contact
cust_email
cust1 8695193 cust1@cust.com
cust10 8695192
cust10@cust.com
cust2
8695194
cust2@cust.com
【示例解析】
返回住在"IL"和"MI"的顾客信息,最后根据顾客名称升序排序。
  • select cust_name, cust_contact, cust_email
    from Customers
    where cust_state = 'MI'
    and cust_state = 'IL'
    order by cust_name;
  • (SELECT cust_name, cust_contact, cust_email
    FROM Customers
    WHERE cust_state = 'MI'
    ORDER BY cust_name)
    UNION all
    (SELECT cust_name, cust_contact, cust_email
    FROM Customers
    WHERE cust_state = 'IL'
    ORDER BY cust_name);
  • select cust_name, cust_contact, cust_email
    from Customers
    where cust_state in ("MI", "IL")
    order by cust_name;
B为什么不行,c的话排序10不应该在最后吗?
发表于 2023-04-01 17:17:16 回复(3)
啥破题啊
发表于 2023-07-05 15:34:38 回复(0)
同问,B为啥不行

发表于 2023-04-04 11:47:08 回复(2)
虽然题格式稀烂,但是还是不错的,帮我复习了一下LEFT JOIN、UNION ALL、JOIN、FULL JOIN的区别
发表于 2024-08-06 20:11:29 回复(0)
总算看完了
发表于 2022-10-18 18:46:31 回复(0)