Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on sql querry within the SQL forums, part of the Databases category; 1) I want to know the sql querries for the following a. To find second largest salary of an employee in a table. b. To find minimum average salary. c. ...
|
|||||||
|
|||
|
sql querry
1) I want to know the sql querries for the following
a. To find second largest salary of an employee in a table. b. To find minimum average salary. c. Querry to fetch current date in SQL SERVER. 2) wat is the difference between GROUP BY and HAVING clauses. |
| Sponsored Links |
|
|||
|
Re: sql querry
@sumangala,
To find second largest salary of an employee in a table. Code:
SELECT * FROM ( SELECT e.deptno , e.ename , e.sal , dense_rank() OVER ( ORDER BY max(e.sal) DESC) Highest_Salary FROM emp e, dept t where e.deptno=t.deptno group by e.deptno,e.ename,e.sal) where Highest_Salary=2; Code:
select min(avg(sa)) from emp group by sal; I have no experience in SQL SERVER I believe the following one get the system date and time . select getdate() In Oracle SQL. (Only date) : Select sysdate from dual; (date with timestamp): Select systimestamp from dual; Difference between GROUP BY and HAVING clauses Group by Clause: Suppose if aggregate functions are included in the select list, finds a summary value for each group.To group the result-set by one or more columns. Having Clause: Since where keyword cant be used with aggregate functions, we go for having clause. Last edited by ecearund; 08-20-2009 at 08:14 AM. |
| The Following User Says Thank You to ecearund For This Useful Post: | ||
|
|||
|
Re: sql querry
to find the second largest salary we can have query as follows
select max(salary) from emp where salary < (select max(salary) from emp) Last edited by prabhakaranspn; 08-23-2009 at 01:33 PM. |
| The Following User Says Thank You to prabhakaranspn For This Useful Post: | ||
|
|||
|
Re: sql querry
Hi difference between group by and having classes the group by and having clauses are used together. The having clause is used as a final filter (rather than as a conditional filter) on the aggregate column values in the result set of a select statement. In other words, the query has to be grouped before the having clause can be applied. For example, consider the following statement, which displays the count of students in various classes (classes of students = 1, 2, 3, 4, corresponding to freshman, sophomore, and so on to get current data there are three ways to retrieve the current datetime in sql server. Current_timestamp, getdate(), {fn now()} current_timestamp current_timestamp is a nondeterministic function. Views and expressions that reference this column cannot be indexed. Current_timestamp can be used to print the current date and time every time that the report is produced. Getdate() getdate is a nondeterministic function. Views and expressions that reference this column cannot be indexed. Getdate can be used to print the current date and time every time that the report is produced. {fn now()} the {fn now()} is an odbc canonical function which can be used in t-sql since the ole db provider for sql server supports them. {fn now()} can be used to print the current date and time every time that the report is produced. If you run following script in query analyzer. I will give you same results. If you see execution plan there is no performance difference. It is same for all the three select statement. Select current_timestamp go select {fn now()} go select getdate() go thanks sushma
|
| The Following User Says Thank You to Sushma Mosali For This Useful Post: | ||
|
|||
|
Re: sql querry
To find the second highest salary of an employee
select * from emp where sal=(select max(sal) from select * from emp minus select * from emp where sal=(select mxa(sal) from emp)); Last edited by chiru0106; 09-07-2009 at 08:35 AM. |
|
|||
|
Re: sql querry
to find the minimum avg salary the query is
select min(avg(sa)) from emp group by sal; 2. the diffrence between group by and having is :- group by is not to produced a desired sequence, but to collect the like things together.whereas having function is very much realated to the where caluseexcept that its logic s related to only only group functions |
|
|||
|
Re: sql querry
to find minimum u can use min(Average salary)
|
|
|||
|
Re: sql querry
Hi, i'm ganesh form vels college of sceince.. Thanks for all. I've a doubt.. I created a table with the following query.. Create table family (name varchar2(20), age number(3)); desc family; name varchar2(20)
age number(3) now i want to add one more fields called gender.. I use the query alter table add gender varchar2(1); now desc family displays name varchar2(20) age number(3) gender varchar2(1) but i want to save the gender field in second position. I.e exactly after the name field.. Can any one help me.. Thank in advance.. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sql querry | sumangala rk | Job Offers | 0 | 08-19-2009 11:45 AM |