Jump to content

SQL server query experts pls come here


Rabbo

Recommended Posts

I have a query which pulls 207K records,

i have to add 2 columns (month and year will be columns ) for the last 2 years 

 

a,b,c are  columns from query1 , month and year will be from query 2

 i need same rows from query1 and query 2  rows change with month and year

ila undhali result set 

a|b|c                  |month|year

207 records ki  a|b|c|nov|2019

same 207k records   a|b|c|oct|2019

and so on  upto last 2 years which will be a|b|c|nov|2017

 

so total records will be 207K * 24 =5,589 K records

Link to comment
Share on other sites

1 minute ago, naaistamrabhai said:

question ardam kale...tables endi...data endi...

Table 1       Table 2

a|b|c|           oct|2019

 

after query

Table 1

a|b|c|oct|2019

a|b|c|sep|2019

a|b|c|aug|2019

.......

a|b|c|oct|2017

Link to comment
Share on other sites

1 minute ago, Spartan said:

Table 1       Table 2

a|b|c|           oct|2019

 

after query

Table 1

a|b|c|oct|2019

a|b|c|sep|2019

a|b|c|aug|2019

.......

a|b|c|oct|2017

join cheste set kada on the primary key 

wht do u need simple no 

Link to comment
Share on other sites

1 hour ago, Rabbo said:

I have a query which pulls 207K records,

i have to add 2 columns (month and year will be columns ) for the last 2 years 

 

a,b,c are  columns from query1 , month and year will be from query 2

 i need same rows from query1 and query 2  rows change with month and year

ila undhali result set 

a|b|c                  |month|year

207 records ki  a|b|c|nov|2019

same 207k records   a|b|c|oct|2019

and so on  upto last 2 years which will be a|b|c|nov|2017

 

so total records will be 207K * 24 =5,589 K records

U should not do that...asal req endi sakkaga seppu jara

Link to comment
Share on other sites

1 hour ago, Rabbo said:

I have a query which pulls 207K records,

i have to add 2 columns (month and year will be columns ) for the last 2 years 

 

a,b,c are  columns from query1 , month and year will be from query 2

 i need same rows from query1 and query 2  rows change with month and year

ila undhali result set 

a|b|c                  |month|year

207 records ki  a|b|c|nov|2019

same 207k records   a|b|c|oct|2019

and so on  upto last 2 years which will be a|b|c|nov|2017

 

so total records will be 207K * 24 =5,589 K records

You will add columns ( year and month) based on identifier on Table B. 

Is that identifier in table A? 

If so just join on that column. 

 

Link to comment
Share on other sites

1 hour ago, Spartan said:

Table 1       Table 2

a|b|c|           oct|2019

 

after query

Table 1

a|b|c|oct|2019

a|b|c|sep|2019

a|b|c|aug|2019

.......

a|b|c|oct|2017

Question baga ardam ayyindhi neeku

Answer cheppu  bro ..

cross join use cheste time out avthundi 

table 2 is just generating month and year for last 2 years 

 

Link to comment
Share on other sites

1 hour ago, Amrita said:

You will add columns ( year and month) based on identifier on Table B. 

Is that identifier in table A? 

If so just join on that column. 

 

Identifier ledu on table b

Link to comment
Share on other sites

18 minutes ago, Rabbo said:

Question baga ardam ayyindhi neeku

Answer cheppu  bro ..

cross join use cheste time out avthundi 

table 2 is just generating month and year for last 2 years 

 

since there is no common identifier...u can try to do UNION

 

SELECT column1, column2, etc FROM table1
UNION
SELECT column1, column2, etc FROM table2
Link to comment
Share on other sites

2 hours ago, Rabbo said:

I have a query which pulls 207K records,

i have to add 2 columns (month and year will be columns ) for the last 2 years 

 

a,b,c are  columns from query1 , month and year will be from query 2

 i need same rows from query1 and query 2  rows change with month and year

ila undhali result set 

a|b|c                  |month|year

207 records ki  a|b|c|nov|2019

same 207k records   a|b|c|oct|2019

and so on  upto last 2 years which will be a|b|c|nov|2017

 

so total records will be 207K * 24 =5,589 K records

https://stackoverflow.com/questions/1797785/sql-join-two-tables-without-keys-relations

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...