Solved

select (count(job) + job)  from AceData  group by job ??

Posted on 2012-12-27
8
215 Views
Last Modified: 2012-12-30
select (count(job) + job)  from AceData  group by job

using ms sql server

the above not working

want to show,

25 myJob
30 otherjob
01 badjob
0
Comment
Question by:goodk
8 Comments
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 167 total points
Comment Utility
you mean to say uou need to show job name also

try tghis

select Cast(count(job) as varchar) + '  ' + job  from AceData  group by job
0
 

Author Comment

by:goodk
Comment Utility
I've requested that this question be deleted for the following reason:

resolved used str() to convert
0
 
LVL 5

Assisted Solution

by:RehanYousaf
RehanYousaf earned 166 total points
Comment Utility
I dont think using STR function is a good idea unless you want fixed length

I would go with pratima's solution
0
 
LVL 31

Accepted Solution

by:
awking00 earned 167 total points
Comment Utility
select job, count(*) cnt from AceDate group by job
will give you two columns, if you want them in one, then

select cast(cnt as char) +  ' ' + job as countjobs from
(select job, count(*) cnt from AceDate group by job)
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:goodk
Comment Utility
I tried this, should this be ok?  The results looks fine
Select (type +' ('+ ltrim(str(count(type))) +')' ) as xtest from AceData group by type
0
 

Author Closing Comment

by:goodk
Comment Utility
thanks
0
 
LVL 5

Expert Comment

by:RehanYousaf
Comment Utility
Yes that will work but why use to functions when you can get away with one

In programming trick is to make things simple not complicated

Select (type +' ('+ convert(varchar,count(type)) +')' )

Open in new window

0
 

Author Comment

by:goodk
Comment Utility
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now