sql - 如何比较具有相同开头和不同结尾的 SQL 条目?
问题描述
基本上,我要比较的行的格式有点像这样:[Form Code]_[Version Date (mm/yy)]。
更新表单时,它们使用相同的代码,但更改版本日期以反映它何时生效。因此,您可能会看到 Example_Code_12_01,然后将其替换为 Example_Code_12_17。
我要做的是编写一个 SQL Server 查询,该查询将遍历这些表单中的每一个,所有表单都具有不同的表单代码,并返回两个具有相同代码但版本日期不同的表单。
我在想它会是这样的:
select a.FullFormName, b.FullFormName
from Forms a
join Forms b on --here is where the logic for the compare would go--
where a.FullFormName != b.FullFormName
--The above is to make sure it doesn't return the same exact form twice
解决方案
您似乎想要在没有最后 6 个字符的情况下进行比较:
select a.FullFormName, b.FullFormName
from Forms a join
Forms b
on left(a.FullFormName, len(a.FullFormName) - 6) = left(b.FullFormName, len(b.FullFormName) - 6) --here is where the logic for the compare would go--
where a.FullFormName <> b.FullFormName;
推荐阅读
- python - 获取方法抛出错误,不知道为什么
- javascript - 我在节点 js 中找不到模块错误并尝试了一切
- c++ - 如何使用 gdb 调试 SIGSEGV
- outlook - 在 Outlook 加载项中的 Office.js 中,如何在发送前 * 消除新撰写的电子邮件?
- java - 堆栈中的方法调用如何执行 - 递归
- node.js - 通过 nvm 安装 Nodejs 时 npm list -g 无法工作
- flutter - 在 TextField 上重新聚焦问题,光标未显示在正确位置
- flutter - 使用 Flutter 进行广播流式传输 just_audio
- html - 如何在不移动元素的情况下为 div 提供边距?
- python - 如何将 Pmw 工具提示添加到 tkinter 画布中的矩形对象?