sql Query

General
Enthusiast

sql Query

I have a requirement for the below query . my query is not working. can someone assist

 

  Step1 :  select statement to select the last entry for all zipCODES from table1 where X_CD = 'C'
Step 2: Provide the count of zipcodes which have Y_CD = 'A'

1 REPLY
Teradata Employee

Re: sql Query

 

Query 1 should look like :

 select *
   from table1
  where X_CD = 'C'
qualify row_number() over(partition by ZipCode order by insert_date desc) = 1

Query 2 :

select count(*), count(distinct ZipCode) -- I can't know without more info
  from table1
 where Y_CD = 'A';

But it's mostly a guess, for a more complete answer you have to provide more intel on the table(s) and the data.