- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
首先,我将解释我的场景。这是正在使用的 2 个通用表:
帐户:
LegacyID = The identifer of theaccount
InvoiceAccount = An account can havemultiple subaccounts in the sametable. This field is the LegacyIDof its parent account
Customer = There can be two differenttypes of accounts, and they can shareID's - so this column differentiatesbetween the 2. For the purposes of mySQL I always want it to be true ratherthan false
AllocatedUser = The username of theperson who needs to see thisdeliveries. This is only populated onthe parent account, so I need to linkback to get this for the subaccounts
交付:
LegacyID = The deliveries identifier
Customer = The LegacyID of the accountrelated to the delivery (can be asubaccount)
OnHold = A flag which for the purposesof my query needs to be 'true'
现在已经解释过了,基本上我需要一个 SQL 来返回任何“暂停”的交付,但仅限于分配给登录用户的帐户的交付。如果传递链接到父帐户,则选择 AllocatedUser 的查询很简单,但如果传递链接到子帐户,我会遇到返回行的问题 - 它根本不返回任何内容。下面是 SQL:
SELECT Deliveries_1.LegacyID, Deliveries_1.TripDate, Deliveries_1.OnHoldReason, Account_2.AllocatedUser
FROM Deliveries AS Deliveries_1 INNER JOIN
Account AS Account_1 ON Deliveries_1.Customer = Account_1.InvoiceAccount INNER JOIN
Account AS Account_2 ON Account_1.InvoiceAccount = Account_2.LegacyID
WHERE (Deliveries_1.OnHold = @OnHold) AND (Account_2.Customer = 'True') AND (Account_2.AllocatedUser = @AllocatedUser)
我的思绪因试图弄清楚为什么它现在不起作用而感到疲倦 - 我真的很感激任何建议。
谢谢!
最佳答案
听起来您正在 Deliveries
表中查找与用户帐户、用户的直系父级帐户和用户的直系子级帐户关联的记录。如果这是真的,按如下方式修改您的查询应该可以解决问题。
SELECT DISTINCT d.LegacyID, d.TripDate, d.OnHoldReason,
case
when child.LegacyID = d.Customer then child.AllocatedUser
when parent.LegacyID = d.Customer then parent.AllocatedUser
else this.AllocatedUser
end as 'Delivery_AllocatedUser'
FROM Account this
LEFT JOIN Account parent on parent.LegacyID = this.InvoiceAccount
LEFT JOIN Account child on this.LegacyID = child.InvoiceAccount
JOIN Deliveries d on (d.Customer = this.LegacyID AND this.Customer = 'True')
OR (d.Customer = parent.LegacyID AND parent.Customer = 'True')
OR (d.Customer = child.LegacyID AND child.Customer = 'True')
WHERE d.OnHold = @OnHold
AND this.AllocatedUser = @AllocatedUser
关于c# - SQL 让我头疼 - 多个连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4316416/
前言 最近有个网友问了我一个问题:系统中大事务问题要如何处理? 正好前段时间我在公司处理过这个问题,我们当时由于项目初期时间比较紧张,为了快速完成业务功能,忽略了系统部分性能问题。项目顺利上线后,
我有以下目录结构: Main.py A/ __init__.py B/ __init__.py C/ __init__.py 文
这个头疼,所以有人可以给我留言吗? XML 就是这样(不是真正的东西,但为了清楚起见,这是一个示例):
本文全面探讨了卷积神经网络CNN,深入分析了背景和重要性、定义与层次介绍、训练与优化,详细分析了其卷积层、激活函数、池化层、归一化层,最后列出其训练与优化的多项关键技术:训练集准备与增强、损失
我的设置: Node.js 蒙古人 一个包含两个集合的简单数据库 - 库存和发票。 用户可以同时创建发票。 一张发票可能涉及多个库存项目。 我的问题: 保持库存完整性。想象一个场景,两个用户提交两张带
这一直是困扰我的问题,人品问题。我总是试图用小补丁来解决我的问题,实际上这从来没有解决我的问题。所以我正在寻找解决所有这些问题的非常强大的解决方案。我想了解大型应用程序(facebook,google
由于完全不受我控制的决定,我处于以下情况: 我在catalog.org 上有一个产品列表 单击产品上的“添加到购物车”按钮向 secure.com/product/add/[productKey] 发
我是一名优秀的程序员,十分优秀!