sql - Select rows with unique attribute -
i have following table
ind_id name value date ----------- -------------------- ----------- ---------- 1 10 2010-01-01 1 20 2010-01-02 1 30 2010-01-03 2 b 40 2010-01-01 2 b 50 2010-01-02 2 b 60 2010-01-03 2 b 70 2010-01-04 3 c 80 2010-01-01 3 c 90 2010-01-02 3 c 100 2010-01-03 3 c 110 2010-01-04 3 c 120 2010-01-05 4 d 130 2010-01-05
how can select rows unique ind_id
attribute? no matter rows each ind_id
. need 4 rows in result set. i'm using sql server 2008. thanks
for this, want use windows functions:
select ind_id, name, value, date (select t.*, row_number() on (partition ind_id order (select null)) seqnum t ) t seqnum = 1;
if want ones appear once, use:
select ind_id, name, value, date (select t.*, count(*) on (partition ind_id) numinds t ) t numinds = 1
Comments
Post a Comment