zoukankan      html  css  js  c++  java
  • 1581. 进店却未进行过交易的客户

    表:Visits

    +-------------+---------+
    | Column Name | Type |
    +-------------+---------+
    | visit_id | int |
    | customer_id | int |
    +-------------+---------+
    visit_id是该表的主键。
    该表包含有关光临过购物中心的顾客的信息。
     

    表:Transactions

    +----------------+---------+
    | Column Name | Type |
    +----------------+---------+
    | transaction_id | int |
    | visit_id | int |
    | amount | int |
    +----------------+---------+
    transaction_id 是此表的主键。
    该表包含有关光临过购物中心的顾客的信息。
     

    编写一个 SQL 查询来查找没有进行任何交易的访问用户的 ID ,以及他们进行这些访问的次数。

    返回以任何顺序排序的结果表。

    解题代码:

    select v.customer_id,count(*) as count_no_trans from Visits v 
    where v.visit_id not in (select visit_id from Transactions)
    group by v.customer_id
    order by count_no_trans desc
  • 相关阅读:
    L7-1 文本处理
    L6-14 继承多态
    L6-13 魔法方法
    L6-12 类的实例
    L6-11 综合运用
    L6-2 嵌套循环
    golang 关于引用类型
    golang close for channel
    go tip
    vscode官方文档
  • 原文地址:https://www.cnblogs.com/tomorrow-hope/p/13834339.html
Copyright © 2011-2022 走看看