if-statement - 客户有多个账户
问题描述
客户表:( 格式:customer_ID Name)
- 101史密斯
- 102 威廉姆斯
- 103 马丁
- 104 杰克
账户表 (格式:Account_ID、customer_ID、Account_Type)
Account_ID customer_ID Account_Type
201 101 A1
202 101 B1
203 101 C1
301 102 B1
302 102 C1
401 103 A1
402 103 C1
501 104 B1
如果一个客户有多个账户,我们根据这个顺序选择account_type:A1,C1,B1
结果应该是:
- customer_ID Account_Type
- 101 A1
- 102 C1
- 103 A1
- 104 B1
我写了以下查询: 选择 c.customer_ID, case when Account_Type in ('A1','B1' 'C1' ) then A1 when Account_Type in (''B1' 'C1' ) then C1 else Account_Type End From customer c join a.customer_ID=c.customer_ID 上的帐户 a
我该如何提出条件:一个客户在此查询中有多个帐户?
谢谢
解决方案
简单的解决方案是
SELECT * FROM (SELECT *, CASE AccountType WHEN 'A1' THEN 1 WHEN 'B1' THEN 3 WHEN 'C1' THEN 2 END As Rank1 FROM testAccount ) 按 CustomerID 排列的订单,Rank1
推荐阅读
- java - 如何使用 Azure DevOps 发布管道将 Java 应用程序部署到 Tomcat 8 App Service?
- gradle - Liquibase groovy dsl 说 Unrecognized root element changeSet
- android - 在 Android Parcelable 类中读取和写入长对象
- css - 在固定导航栏之后定位内容?
- vue.js - 如何测试 vue-js-modal 组件?
- json - 我无法呈现作为响应显示的 JSON 对象
- java - 即使电子邮件存在于 Firebase 中也会出现 400 错误
- cassandra - Cassandra 触发异常:InvalidQueryException:附加突变表与主更新表不匹配
- docker - 无法使用 docker-compose 连接到 kibana/elasticsearch
- linux - linux:如何以递归方式批量重命名文件和目录?