Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write a single SQL to delete duplicate records from the a
single table based on a column value. I need only Unique
records at the end of the Query.

Answer Posted / jaya

/********maximum salary of each dept*************/



sel * from vik_emp where (salary, dept_id) in (sel max
(salary), dept_id from vik_emp group by dept_id);



sel emp_id, emp_name, a.salary, a.dept_id from vik_emp a

inner join

(sel max(salary) as salary, dept_id from vik_emp group by
dept_id) b

on

a.salary=b.salary

and

a.dept_id=b.dept_id;





/*********top 3 salary of each dept*********/

sel distinct

emp_name,

salary,

Dept_id,

rank() over (partition by dept_id order by salary desc )
rk ,

row_number() over (partition by dept_id order by salary
desc )rn

from vik_emp

order by dept_id, rk, rn

QUALIFY rn <= 3;





/*****cutomer having only one type of account******/



sel cust_nm, acctyp from cust where cust_nm not in

(sel a.cust_nm as cust_nm from cust a

inner join cust b on

a.cust_nm= b.cust_nm

and

a.acctyp <> b.acctyp);



/************coustomer with types of acc they
have***************/



select cust_nm, max(acctyp1), max(acctyp2)

--, max(srv_need3)

from

(

select cust_nm,

case when acctyp = 'saving' then acctyp else null end as
acctyp1,

case when acctyp = 'credit' then acctyp else null end as
acctyp2

--,case when srv_need = 30 then srv_need else null end as
srv_need3

from

cust

)a

group by 1;





/* How to Extract Middle name from the Full name */



select emp_name,

index(emp_name,' ') as a,

substr(emp_name,a+1) as rest_name,

substr(rest_name,1,index(rest_name,' ')) as Middle_Name

from vik_emp;





select emp_name,

--index(emp_name,' ') as a,

substr(emp_name,index(emp_name,' ') +1) as rest_name,

substr(rest_name,1,index(rest_name,' ')) as Middle_Name

from vik_emp;

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the new features of teradata?

992


Which is more efficient group by or distinct to find duplicates?

1036


What are the components provided on node?

986


How do you determine the number of sessions?

1010


What is the use of fallback?

941


Why does varchar occupy 2 extra bytes?

1107


What is spool space? Why do you get spool space errors?

949


How many types of joins are there in teradata?

916


What are the different softwares used with their functions in teradata?

968


In a table can we use primary key in one column and in another column both unique and not null constrains.if yes how?

1094


Comment whether bottleneck is an error or not.

1074


What are the frequently used data types in teradata?

1006


What is spool space? Why do you get spool space errors? How do trouble-shoot them?

930


How to run a query in teradata?

1010


What is the command in bteq to check for session settings ?

1116