Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > sum () Over ( Partition by )

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-07, 06:53
neerajrathi2 neerajrathi2 is offline
Registered User
 
Join Date: Sep 2007
Posts: 6
sum () Over ( Partition by )

Hello
Is there in option in SYBASE ASE's T-sql to obtain sum of columns over window formed by partitooning table.

In Oracle we could write it as

SELECT SUM(Column1) over ( Partition BY Column 2) from dual;

But same query give error in SYBASE ASE.

Sybase manulas say Sybase IQ support such query.
Please suggest some alternative.
Reply With Quote
  #2 (permalink)  
Old 11-15-07, 10:39
db2hrishy db2hrishy is offline
Registered User
 
Join Date: Jun 2004
Posts: 109
you need to do it t-sql using multiple temp tables
Reply With Quote
  #3 (permalink)  
Old 11-16-07, 03:27
neerajrathi2 neerajrathi2 is offline
Registered User
 
Join Date: Sep 2007
Posts: 6
How ? Could you please explain a bit more. In oracle query is as below

Select rpt_maj_cat , sum(sum(mkt_ord_cnt)) over ( partition by rpt_maj_cat) from Ac1_6 where qtr=3 group by rpt_maj_cat,venue
Reply With Quote
  #4 (permalink)  
Old 11-19-07, 02:28
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 830
Can you give some sample data and the expected output
Why do you have sum(sum seems unnecessary
Your grouping seem inconsistent - venue is not in the select list
Reply With Quote
  #5 (permalink)  
Old 11-19-07, 02:48
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 830
Maybe this example can help you
Code:
create table #testdata (DEPNO int, ENAME varchar(20), SAL int) insert into #testdata select /* DEPNO ENAME SAL ------ ---------- ---------- */ 10,'MILLER' , 1300 union all select 10,'CLARK ' , 2450 union all select 10,'KING ' , 5000 union all select 20,'SMITH ' , 800 union all select 20,'ADAMS ' , 1100 union all select 20,'JONES ' , 2975 union all select 20,'FORD ' , 3000 union all select 20,'SCOTT ' , 3000 union all select 30,'JAMES ' , 950 union all select 30,'MARTIN' , 1250 union all select 30,'WARD ' , 1250 union all select 30,'TURNER' , 1500 union all select 30,'ALLEN ' , 1600 union all select 30,'BLAKE ' , 2850 select a.*, b.DEPSAL from #testdata a join (select DEPNO, sum(SAL)DEPSAL from #testdata group by DEPNO) b on a.DEPNO=b.DEPNO drop table #testdata DEPNO ENAME SAL DEPSAL ----------- ----- ----------- ----------- 10 MILLER 1300 8750 10 CLARK 2450 8750 10 KING 5000 8750 20 SMITH 800 10875 20 ADAMS 1100 10875 20 JONES 2975 10875 20 FORD 3000 10875 20 SCOTT 3000 10875 30 JAMES 950 9400 30 MARTIN 1250 9400 30 WARD 1250 9400 30 TURNER 1500 9400 30 ALLEN 1600 9400 30 BLAKE 2850 9400
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On