求高手改造SQL

taolinsen 2012-03-06 09:52:03
Oracle 11下,查询表tgt_borwreturnschedule 中日期最小的并且非最后一条的记录,菜鸟SQL如下:

select a.*
from tgt_borwreturnschedule a,
(select t.tradeid, min(t.paydate) paydate
from tgt_borwreturnschedule t
where t.paydate < (select max(paydate)
from tgt_borwreturnschedule t1
where t1.tradeid = t.tradeid)
group by t.tradeid) v
where a.tradeid = v.tradeid
and a.paydate = v.paydate

盼指点
...全文
136 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huan_lxyd 2012-03-20
  • 打赏
  • 举报
回复
SELECT m.* FROM (SELECT t.*, ROW_NUMBER() OVER(PARTITION BY t.tradeid ORDER BY t.paydate) rn, COUNT(DISTINCT t.paydate) OVER(PARTITION BY t.tradeid) cnt FROM t) m WHERE m.rn = 1 AND m.cnt > 1

学习。。。
啊彪123 2012-03-19
  • 打赏
  • 举报
回复
select 日期最小的 not in (最新的)
JoeBlackzqq 2012-03-18
  • 打赏
  • 举报
回复
"非最后一条记录"到底是个啥定义呀,太模糊了!

难道是:按照记录插入数据库的时间来排序,不是最后插入的,且日期是最小的?
kingkingzhu 2012-03-07
  • 打赏
  • 举报
回复
楼上分析函数应该是可以搞定的 效率应该也不错
hudingchen 2012-03-07
  • 打赏
  • 举报
回复

SELECT m.*
FROM (SELECT t.*,
ROW_NUMBER() OVER(PARTITION BY t.tradeid ORDER BY t.paydate) rn,
COUNT(DISTINCT t.paydate) OVER(PARTITION BY t.tradeid) cnt
FROM t) m
WHERE m.rn = 1
AND m.cnt > 1
lxyzxq2008 2012-03-06
  • 打赏
  • 举报
回复
你的这个非最后一条记录很模糊啊,而且你写的sql我都快看晕了
我理解的是同一个tradeid下的非最后一条记录。

select tradeid, min(paydate),count(tradeid) from tgt_borwreturnschedule
group by tradeid
having count(tradeid) > 1

你不会想说的是整个表的非最后一条记录,也就是只有一条记录的时候吧??
因为如果是表中的非最后一条记录的话,那么如果你的表中有相同的两个最小日期,好像就没办法做了啊?
软件保护与破解始终在战斗中发展,本资源提供的软件保护程序为.net源代码。破解软件为reflector,收集了所有的插件,大部分为源代码 (软件保护源代码可是找了一年才找到,可是源代码啊,对研究软件保护技术太有帮助了,基本上保护措施都有了,可以参见www.pediy.com网站出的书,我改造了一下在自己产品中使用,对reflector进行了防护,改造的程序不放出也不卖,否则高手知道我怎么防护的就很容易写个reflector插件破解我产品了,大家可以拿代码研究自己改造,最好参考单海波等人写的《微软.net程序加密与解密》这本书,不是为他们书做广告,因为是2008年出版的,想买可能也买不到了,基本上把书里讲到的软件保护技术都实现了,如果不是源代码出自国外牛人,还真认为他们是一伙的) 软件保护支持特性: 1. Name Obfuscation 2.User Strings Encryption 3.Proxy for external/internal 4.constructors/methods 5.Adding Incorrect Metadata 6.Control Flow Obfuscation 7.Compress Output Assembly 反编译reflector软件插件列表: 1.CodeMetrics: Analyses .NET assemblies and shows design quality metrics. 2.Review: Allows editing and managing annotations during code reviews. 3.Diff: This add-in shows differences between two versions of the same assembly. 4.Pex: Use the Pex Wizard directly from Reflector (requires .NET 2.0) 5.Snippy: Snippy is a light weight snippet compiler integrated into .NET Reflector. 6.SilverlightLoader: Allows browsing the structure of a website and loading Silverlight assemblies. 7.FileDisassembler: This add-in can be used to dump the disassembler output to files for any Reflector supported language. 8.Reflexil: Allows to manipulate the IL of a loaded assembly, or inject VB.net/C# code, then write the changes to disk. 9.BamlViewer: Load BAML resources (WPF) and render in XAML format. 10.SilverlightBrowser: Loads and shows the files associated with a Silverlight website. 11.ComLoader: Lists COM components for browsing and converts them into managed interop assemblies. 12.SQL2005Browser: This add-in allows to browse .NET assemblies stored in SQL Server 2005 databases. 13.FileGenerator: This add-in can be used to dump the disassembler output to files for any Reflector supported language. 14.Deblector: This add-in allows to debug processes from within Reflector. 15.Doubler: A code generator for unit tests, stubs and wrappers. 17.Graph: This add-in draws assembly dependency graphs and IL graphs. Please read the install instructions here. 18.BizTalkDisassembler: Allows you to list all BizTalk artifacts contained in an assembly and extract them. 19. DependencyStructureMatrix: Allows you to create and browser dependency structure matrices. 20.CodeSearch: This add-in allows searching for strings and regular expressions in disassembled code. 21.RuleSetEditor: Editor for Windows Workflow Foundation rules. 22.AssemblyListEx:Register a file type association for predefined lists of assemblies to load into Reflector. 23.SequenceViz: This add-in draws sequence diagrams. 24.AutoDiagrammer: This add-in draws class diagrams. 25.Xmi4DotNet: Export an assembly to XMI/UML. 26.AssemblyCollectionSort: Sorts the current assembly list alphabetically. 27.Enums: Conversion of big flags and enum viewer. 28.PowerShellLanguage: Renders output as Windows PowerShell script. 29.DelphiLanguage: The Delphi view that is used inside .NET Reflector provided as a language add-in. 30.CppCliLanguage: This add-in extends Reflector with a C/CLI language rendering module. 31. ReflectionEmitLanguage: This add-in renders C# code necessary to create the given IL body. 32. TestDriven.net: This Visual Studio add-in can navigate to any code element inside Reflector with a single click. 33. Hawkeye: A tool that allows you to debug the UI tree of Windows Forms applications. 35. ClassView: Shows class definitions as plain text with color coding. 36. CodeModelViewer: This add-in shows the underlying code model objects for selected items.

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧