This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Examples of Partition, Row Over to find duplicate queries  RSS feed

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

-- Here i wanted to find out rows that have duplicate values in 2 columns, and find out the lesser id on these 2 rows.
select * from (SELECT ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY colid DESC) as row_number,
colid, col1, col2, col3, col4 from <some table> ) where row_number = 2;


-- here i wanted to find out latest bonds records a history table that tracks various status that a bond can have.
select a.bond_key, a.bond_status_tp_cd, a.status_date, a.maximum_date from
(select bond_key, bond_status_tp_cd, status_date, max(status_date)
OVER (PARTITION BY bond_key) as maximum_date from oltp.bond_status_history) a ,
oltp.bond b where b.bond_key = a.bond_key and a.status_date = a.maximum_date and b.IBL_CREATN_IND = 'Y' and a.bond_status_tp_cd in ('25', '100','110','109');


 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!