Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqldba2k6
Posting Yak Master
176 Posts |
Posted - 2006-10-30 : 11:15:59
|
| Hi all,I have a table with the following information:MytableColumn1 Column2 103 1103 1104 NULL104 NULL105 1105 1105 NULL105 1106 0106 0106 0106 NULLI want the output below:column2 count1 20 1 I want to show count as 1 even though there are more than one values.How can i achieve this? Thanks for the help in advance |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-30 : 11:23:47
|
| select column2, count(distinct column1) from mytable group by column2Peter LarssonHelsingborg, Sweden |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-10-30 : 11:25:47
|
select sign(count(*))from ...Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-30 : 20:18:54
|
quote: column2 count1 20 1
How do you expect count for 1 to be 2?MadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-31 : 00:46:55
|
Madhi, see my query above. Or this enhanced versionselect column2, count(distinct column1) [count]from mytablewhere column2 is not nullgroup by column2order by column2 desc Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-31 : 09:16:05
|
Thanks Peso MadhivananFailing to plan is Planning to fail |
 |
|
|
sqldba2k6
Posting Yak Master
176 Posts |
Posted - 2006-10-31 : 11:27:29
|
| Thanks peso ! i got the results with your query |
 |
|
|
|
|
|