Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:25:28+00:00 2026-06-16T01:25:28+00:00

EDIT Here is an example of my data: create TABLE #Table ( [Market] VARCHAR(100),

  • 0

EDIT

Here is an example of my data:

 create TABLE #Table 
(
    [Market] VARCHAR(100),
    [Operator] VARCHAR(100),
    [Date] DATE,
    [Num Registrations] INT,
    [Num Active] INT,
    [Num Accepted Purchases] INT
)

INSERT INTO #Table VALUES
('Market1','Operator1','2012-12-01',2,4,7),
('Market1','Operator2','2012-12-01',3,5,7),
('Market1','Operator3','2012-12-01',1,2,7),
('Market2','Operator4','2012-12-01',2,1,7),
('Market2','Operator5','2012-12-01',0,4,7),
('Market3','Operator6','2012-12-01',2,44,7)

I have the following script:

SELECT 
    a.[Market],
    a.[Operator],
    a.[Date],
    a.[Num Registrations],
    a.[Num Active],
    a.[Num Accepted Purchases],
    [rnk] = b.rnk
FROM 
    #Table a
    INNER JOIN 
        (
        SELECT 
            [Market],
            [rnk] = RANK() OVER (ORDER BY SUM([Num Registrations] + [Num Active]))
        FROM #Table
        GROUP BY [Market]
        ) b
        ON 
          a.[Market] = b.[Market]
GROUP BY
    a.[Market],
    a.[Operator],
    a.[Date],
    a.[Num Registrations],
    a.[Num Active],
    a.[Num Accepted Purchases],
    b.rnk

The above works ok but have I over-complicated things with the sub-query; could I have used the RANK function directly in the main query’s SELECT clause?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:25:29+00:00Added an answer on June 16, 2026 at 1:25 am

    Yes, you don’t need to do an explicit join at all:

    SELECT distinct
        a.[Market],
        a.[Operator],
        a.[Date],
        a.[Num Registrations],
        a.[Num Active],
        a.[Num Accepted Purchases],
        [rnk] = dense_rank() over (order by tot, market)
    FROM (select a.*,
                 sum(a.[Num Registrations] + a.[Num Active]) over (partition by market) as tot
          from xxx.dbo.tb_r12044dxx_yyyy a
         ) a
    

    If you don’t have duplicates, then you can remove the distinct from the select.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Here's a create script for the table minus the constraints on the keys
I have a MySQL table with the following columns: id(int), date (timestamp), starttime(varchar), endtime(varchar),
Table layout: CREATE TABLE t_order (id INT, custId INT, order DATE) I'm looking for
When a user links to link it redirects to edit.php - here's an example:
So here is what the method looks like now: POST person/personId/edit https://api.example.com/*key*/person/*personId*/edit?FName=Blah I want
When inserting values into my table what do I edit here? Do I delete
Assuming I have something along the lines of this example: CREATE TABLE NaiveTable {
I'm trying to create a form whose layout is entirely data driven. Example data
Im trying to hammer togehter a WYSIWYG-edit in c# following some examples from here
EDIT: Here is the edited control file (control.ascx): <%@ Control Language=C# AutoEventWireup=true CodeFile=Sale.ascx.cs Inherits=Enmasse.Modules.Demo_Enmasse.Sale

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.