Add prefix to top 10 query (1 Viewer)

gojets1721

Registered User.
Local time
Yesterday, 23:03
Joined
Jun 11, 2019
Messages
430
I have a query which groups and counts values, and only shows the ten highest (SELECT TOP 10). It basically looks like this:

SubCategoryCountofSubCategory
Henry67
John53
....and so on

I want to add a prefix number to the subcategory field so that it basically shows up as:

SubCategoryCountofSubCategory
1. Henry67
2. John53
...and so on

Suggestions on if that's possible? I can post my SQL code if beneficial
 

cheekybuddha

AWF VIP
Local time
Today, 07:03
Joined
Jul 21, 2014
Messages
2,280
If you have saved your query (eg 'qrySubCategoryCounts'), you should be able to do something like:
SQL:
SELECT
  c.Counter & '. ' & a.SubCategory AS SubCategory,
  a.CountOfSubCategory
FROM qrySubCategoryCounts a
INNER JOIN (
  SELECT
    COUNT(*) AS Counter
  FROM qrySubCategoryCounts b
  WHERE b.CountOfSubCategory <= a.CountOfSubCategory
) c
ORDER BY
  a.CountOfSubCategory DESC;
(NB Untested!)
 

tvanstiphout

Active member
Local time
Yesterday, 23:03
Joined
Jan 22, 2016
Messages
222
I have a query which groups and counts values, and only shows the ten highest (SELECT TOP 10). It basically looks like this:

SubCategoryCountofSubCategory
Henry67
John53
....and so on

I want to add a prefix number to the subcategory field so that it basically shows up as:

SubCategoryCountofSubCategory
1. Henry67
2. John53
...and so on

Suggestions on if that's possible? I can post my SQL code if beneficial
 

ebs17

Well-known member
Local time
Today, 08:03
Joined
Feb 7, 2020
Messages
1,946
Untested!
Table a is unknown in subquery c and will throw an error.

SQL:
SELECT
   DCount("*", "qrySubCategoryCounts", "CountOfSubCategory > " & a.CountOfSubCategory) + 1 & '. ' & a.SubCategory AS SubCategory,
   a.CountOfSubCategory
FROM
   qrySubCategoryCounts a
 

gojets1721

Registered User.
Local time
Yesterday, 23:03
Joined
Jun 11, 2019
Messages
430
Table a is unknown in subquery c and will throw an error.

SQL:
SELECT
   DCount("*", "qrySubCategoryCounts", "CountOfSubCategory > " & a.CountOfSubCategory) + 1 & '. ' & a.SubCategory AS SubCategory,
   a.CountOfSubCategory
FROM
   qrySubCategoryCounts a
That worked! Thanks so much!
 

Users who are viewing this thread

Top Bottom