Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 10th, 2006, 04:35 AM
lakshmananl
Guest
 
Posts: n/a
Default Uregent finding difference between count of two coulumns

hi,
i am doing a report generation work in which i take the count of two
columns. and i need to calculate the difference of the counted value as
a new column. for example in SQL we use


<B>difference(count(a.column1),count(a.column2)) as alias <B>

what will be the equivalent statement in DB2

i tried the same in DB2 but i get error.
Kindly help me in this

regards
lakshmanan

  #2  
Old March 10th, 2006, 05:05 AM
Tonkuma
Guest
 
Posts: n/a
Default Re: Uregent finding difference between count of two coulumns

What DBMS are you using?

MS SQL Server 2000 has DIFFERENCE function. But, it's written that
"Returns the difference between the SOUNDEX values of two character
expressions as an integer."

I couldn't find DIFFERENCE function in Oracle 10g SQL Reference.

  #3  
Old March 10th, 2006, 05:15 AM
Tonkuma
Guest
 
Posts: n/a
Default Re: Uregent finding difference between count of two coulumns

If you want difference of two counts, you can get it with this.

ABS(count(a.column1) - count(a.column2)) as alias

  #4  
Old March 10th, 2006, 05:15 AM
lakshmananl
Guest
 
Posts: n/a
Default Re: Uregent finding difference between count of two coulumns

hi i am using DB2 v7.2.9, i tried the example in SQL Server. and i need
the same to be done in the DB2.

the actual report should look like below


col1(count) col2(count) col3(diff of count)
1 1 0
3 1 2



like this i am able to do this in SQL server

kindly help me

regards
lakshmanan

  #5  
Old March 10th, 2006, 01:05 PM
Dave Hughes
Guest
 
Posts: n/a
Default Re: Uregent finding difference between count of two coulumns

lakshmananl wrote:
[color=blue]
> hi i am using DB2 v7.2.9, i tried the example in SQL Server. and i
> need the same to be done in the DB2.
>
> the actual report should look like below
>
>
> col1(count) col2(count) col3(diff of count)
> 1 1 0
> 3 1 2
>
>
>
> like this i am able to do this in SQL server[/color]

Diff of count? Weird syntax. What's wrong with a simple subtraction?

SELECT
COUNT(COL1) - COUNT(COL2) AS COUNTDIFF
FROM SOMETABLE

Or as Tonkuma suggested, throw in a call to ABS() if you don't want
negative values in the result:

SELECT
ABS(COUNT(COL1) - COUNT(COL2)) AS COUNTDIFF
FROM SOMETABLE


HTH,

Dave.

--

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

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

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles