我有一个问题是运行SQL查询。我根据计数得到记录。 [英] I have a problem to run sql query. I am getting the records based on count.
本文介绍了我有一个问题是运行SQL查询。我根据计数得到记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的查询。
Hi,
This is my query.
SELECT top(10) LocationName, companyname, COUNT(LocationName) AS TotalCount
FROM
Job where CountryId = 108 and LocationName !=' ' and CompanyName != ''
GROUP BY companyname ORDER BY TotalCount DESC
我想要这样的结果。
I want result like this.
locationname companyname count
hyderabad IBM 45
Banglooru Satyam 32
like this
my previous query
SELECT top(5) Locationname,
COUNT(Locationname) AS TotalCount
FROM
Job where CountryId = @cntid and Title !=' '
GROUP BY Locationname ORDER BY TotalCount DESC
this query result is
locationname count
hyderabad 45
Banglooru 32
like this,
The first query is not working
please helpme.
Thank you.
推荐答案
你错过了Group BY子句中的LocationName
< br $>
SELECT top(10)LocationName,companyname,COUNT(LocationName)AS TotalCount
FROM
CountryId的工作= 108和LocationName!=''和CompanyName!=''
GROUP BY companyname,LocationName ORDER BY TotalCount DESC
You were missing the LocationName in the Group BY clause
SELECT top(10) LocationName, companyname, COUNT(LocationName) AS TotalCount
FROM
Job where CountryId = 108 and LocationName !=' ' and CompanyName != ''
GROUP BY companyname, LocationName ORDER BY TotalCount DESC
这篇关于我有一个问题是运行SQL查询。我根据计数得到记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文