Search:
www.rocket99.com : Technical Guides Sybase Oracle UNIX Javascript


Technical Guides
Sybase
Oracle
UNIX
Javascript




After Work

Highlife Adventures
The best club in Chicago
for Chicago Singles is Highlife Adventures!


Jersey Girl Shirts
Are you looking for a
Jersey Girl T-Shirt ?



Kyoto Sushi
in Chicago, on Lincoln Ave.
Moody's Pub
in Chicago, has great burgers
Skylark
in Chicago, on Halsted .. excellent Friday fish fry!


Sybase » Transact-SQL » Tips Tricks »

Self-Joins in SQL

     




Below are two SQL statements which can be used for "row numbering" and calculating "cumulative totals". The below versions use self joins to achieve the same.
Thanks to Amit Vidyasagar for this submission.




use pubs2
go

--Numbering Rows
SELECT t1.title_id, "row number" = count(*)
FROM titles t1, titles t2
WHERE t2.title_id <= t1.title_id
GROUP BY t1.title_id
go

--Cumulative Totals
SELECT t1.title_id, t1.advance, "cumulative_total" = SUM(t2.advance)
FROM titles t1, titles t2
WHERE t2.title_id <= t1.title_id
GROUP BY t1.title_id, t1.advance
go












Sybase : Related Topics


Sybase Web Site
Sybase Mobile Web Site
Oracle Web Site





Site Index About this Guide to Sybase, Oracle, and UNIX Contact Us Advertise on this site




Copyright © 2008 Citisoft Inc All Rights Reserved.