By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,004 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,004 IT Pros & Developers. It's quick & easy.

Uregent finding difference between count of two coulumns

P: n/a
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

Mar 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

Mar 10 '06 #2

P: n/a
If you want difference of two counts, you can get it with this.

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

Mar 10 '06 #3

P: n/a
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

Mar 10 '06 #4

P: n/a
lakshmananl wrote:
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


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.

--

Mar 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.