How to solve this query problem for output in sql server

Posted by Cpatil1000 under Sql Server on 12/12/2013 | Points: 10 | Views : 1086 | Status : [Member] | Replies : 5
Hi,
I have written following sql query, but output is not getting proper. It is not showing that state wise proper result.
1. In first sql query I want output my with state and year wise with quarters
2. In second sql query I want out with Quarters if must be compared with Quarter and years . ie.( 'January-March’, 'April-June')

Select DISTRICT_NAME, TOTAL_POPULATION_AS_PER_CENSUS_2011, YEAR From NINTY_SIX_COLUMN_MASTER
Where ((DISTRICT_NAME ='AHMEDNAGAR' and TOTAL_POPULATION_AS_PER_CENSUS_2011 > 500) Or (DISTRICT_NAME ='AKOLA' And TOTAL_POPULATION_AS_PER_CENSUS_2011 < 600))
And (YEAR = 2013 And Quaters ='January-March')


Select DISTRICT_NAME, TOTAL_POPULATION_AS_PER_CENSUS_2011, YEAR From NINTY_SIX_COLUMN_MASTER
Where ((DISTRICT_NAME ='AHMEDNAGAR' and TOTAL_POPULATION_AS_PER_CENSUS_2011 > 500 And YEAR = 2013 And
Quaters ='January-March') Or (DISTRICT_NAME ='AKOLA' And TOTAL_POPULATION_AS_PER_CENSUS_2011 < 600 YEAR = 2013 And Quaters ='April-June'))




Responses

Posted by: Nismeh on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
In first query you can go for UNION key word. That will help you apparently.


IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
Provide data. What u have provided is not sufficient.
From what i've understood,
use Self Join and Group By.


http://hashtagakash.wordpress.com/

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nismeh on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
And one more better way for first query is
Use group by.

IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nismeh on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
Yes also in second query. Group by will be most effective option for you.

IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 12/13/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Can you post the sample data of tables and expected output for both queries so that I can provide you the solution

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response