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

  • Home
  • SEARCH
  • 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 5840457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:44:53+00:00 2026-05-22T11:44:53+00:00

Could you please explain what do these lines of code do? Table 1: INT,VARCHAR,FLOAT

  • 0

Could you please explain what do these lines of code do?

Table 1: INT,VARCHAR,FLOAT

ID Name  value
---------------------------
1   a1  32116580
2   a2  50785384
3   a3  54327508
4   a4  61030844

;with coords(i,row,col,total,N) as (
select 1,1,1,N.N*(N.N+1)/2, N.N
from (select count(*) N from table1) N
union all
select i+1,
       case when col+1>N then row+1 else row end,
       case when col+1>N then row+1 else col+1 end,
       total, N
from coords
where i<total
)

I know with provides a way to write auxiliary statements for use in a larger query, so it is like if I declare some variables I would use, but after that I am a little confused…And Why the use of case for getting row and col; Also why in the case there are two: case when col+1>N then row+1 else , How does SQL know when to do one case or the other?…

i  row col total N
--------------------
1   1   1   10   4
2   1   2   10   4
3   1   3   10   4
4   1   4   10   4
5   2   2   10   4
6   2   3   10   4
7   2   4   10   4
8   3   3   10   4
9   3   4   10   4
10  4   4   10   4
  • 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-05-22T11:44:54+00:00Added an answer on May 22, 2026 at 11:44 am

    The columns of table1 can be ignored since only the count is being used – thus you can rewrite your CTE as:

    ;with coords(i,row,col,total,N) as (
        select 1, 1, 1, 10, 4
        union all
        select i+1,
               case when col+1>N then row+1 else row end,
               case when col+1>N then row+1 else col+1 end,
               total, N
        from coords
        where i<total
        )
    SELECT * FROM coords
    

    …with a SELECT * FROM coords there to visualise the results.

    The select 1, 1, 1, 10, 4 ‘seeds’ the recursion – this is the row from which later levels of the recursion will derive. The rest of the rows are built up from the second query acting upon (initially) the seed row and then the resultant row from the second query fed back in to itself etc.

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

Sidebar

Related Questions

Could someone please explain what is meant by the following ? You must define
Could you please lend a hand as I am having some trouble getting the
How does the following code work even though the signature of the function in
Take the following code example: File package1/__init__.py : from moduleB import foo print moduleB.__name__
I'm very new to C so please bear with me. I am struggling with
I want to show the projects that has had it's checkbox ticked as Branding,
Here's my problem: I have a group of divs which have varying amounts of
Need to calculate optimum ulimit and fs.file-max values according to my own server needs.
I'm just beginning in Jquery and learning pretty quickly, but I spent the past

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.