BookmarkSubscribeRSS Feed
LearnByMistk
Obsidian | Level 7

Hi,

Is this possible to run a query from already written query like

select distinct salary from (select user_id, sum(salary) from emp where month =3 group by user_id) ;

this is an example so consider we are having 10 different sum of salary ...but i want to figure that out from select * from select query ....

Thanks for reverting back ..

3 REPLIES 3
Kurt_Bremser
Super User

Yes, you can do nested queries.

If you want to continue work on a query that is already definied, save it into a table by using create table ... as select ...

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, you can do that no problem, its called a subquery when another one is nestled in brackets.  I would however wonder why you are doing it like that, there are times to use subqueries, however from what you have said and posted, I don't think this is one of them.  Perhaps post some test data and required output.  Just from what you have posted, assuming it is differing months then:

select user_id, sum(salary) from emp group by month,user_id

rather than several queries.  Also note that distinct salary may return more than one row from your query, so how will handle that?

LearnByMistk
Obsidian | Level 7

Yes RW9@ & KurtBremser... i agree there are multiple ways but couldn't bring them that time so used that..

actually i used earlier select a,b from (select id ,cat from T 1 where some condition) aliasname....as i forgot to put this alias name so it makes me to put question  here on discussion portal ...but thanks for the effrort you guys put ..i appreciate it .thanks..

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2970 views
  • 0 likes
  • 3 in conversation