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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need a query to display output as '*'

Author  Topic 

vision99
Starting Member

14 Posts

Posted - 2009-05-26 : 11:25:42
CREATE TABLE #temp1
(
id INT,
)
INSERT INTO #temp1 VALUES('11')
INSERT INTO #temp1 VALUES('11')
INSERT INTO #temp1 VALUES('12')
INSERT INTO #temp1 VALUES('11')
INSERT INTO #temp1 VALUES('11')
INSERT INTO #temp1 VALUES('11')
INSERT INTO #temp1 VALUES('55')
INSERT INTO #temp1 VALUES('66')
INSERT INTO #temp1 VALUES('66')
INSERT INTO #temp1 VALUES('66')
INSERT INTO #temp1 VALUES('66')
INSERT INTO #temp1 VALUES('55')
INSERT INTO #temp1 VALUES('55')

Need a query to display output as below using above #temp1 table.

NOTE : should not do changes the table structure.


*
**
***
****
*****


-Vision

zubamark
Starting Member

23 Posts

Posted - 2009-05-26 : 11:27:49
select * from #temp1
id
-----------
11
11
12
11
11
11
55
66
66
66
66
55
55
(13 row(s) affected)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-26 : 12:12:45
is this a homework question?
Go to Top of Page

vision99
Starting Member

14 Posts

Posted - 2009-05-26 : 12:45:15
quote:
Originally posted by visakh16

is this a homework question?

No!!! This is Interview qus...

-Vision
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-26 : 12:52:45
[code]SELECT REPLICATE('*',Cnt)
FROM
(SELECT COUNT(*) AS Cnt
FROM #Temp
GROUP BY id
ORDER BY Cnt
)t
[/code]
Go to Top of Page

vision99
Starting Member

14 Posts

Posted - 2009-05-26 : 13:11:03
quote:
Originally posted by visakh16

SELECT REPLICATE('*',Cnt)
FROM
(SELECT COUNT(*) AS Cnt
FROM #Temp
GROUP BY id
ORDER BY Cnt
)t




Hi

I tested the query, showing err msg like: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified. so removed the ORDER BY Clause and executed but displaying output like

*****
*
***
****

-Vision
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-26 : 13:15:19
[code]SELECT REPLICATE('*',Cnt)
FROM
(SELECT COUNT(*) AS Cnt
FROM #Temp
GROUP BY id
)t
ORDER BY Cnt
[/code]
Go to Top of Page
   

- Advertisement -