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..

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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