如何过滤仅占用最新更新信息的数据?这是样本数据。
数据:
United States of America 2000 Dentistry personnel density 162.7
United States of America 2000 Health management & support workers 1237.9
United States of America 2000 Laboratory health workers 228.4
United States of America 1995 Nursing and midwifery personnel 879.80005
United States of America 2000 Nursing and midwifery personnel 936.69995
United States of America 2005 Nursing and midwifery personnel 981.49994
United States of America 1995 Other health workers 650.89996
United States of America 2000 Other health workers 1452.1
United States of America 2005 Other health workers 494.3
United States of America 2009 Other health workers 849.89996
United States of America 2010 Other health workers 857.9
United States of America 2011 Other health workers 845.89996
United States of America 2000 Pharmaceutical personnel 87.6
United States of America 2010 Pharmaceutical personnel 88.1
United States of America 1995 Physicians 239.5
United States of America 2000 Physicians 256.4
United States of America 2004 Physicians 267.19998
United States of America 2005 Physicians 240.9
United States of America 2006 Physicians 240.2
United States of America 2007 Physicians 241.00002
United States of America 2008 Physicians 241.59999
United States of America 2009 Physicians 242.2
United States of America 2010 Physicians 241.00002
United States of America 2011 Physicians 245.2
Uruguay 2002 Dentistry personnel density 116.1
Uruguay 2008 Dentistry personnel density 70.1
Uruguay 2008 Health management & support workers 69.5
Uruguay 2008 Laboratory health workers 17.0
Uruguay 2002 Nursing and midwifery personnel 84.899994
Uruguay 2008 Nursing and midwifery personnel 554.8
Uruguay 2008 Other health workers 137.0
Uruguay 2008 Pharmaceutical personnel 53.100002
Uruguay 2002 Physicians 365.19998
Uruguay 2008 Physicians 373.6
我想要的是什么:
United States of America 2000 Dentistry personnel density 162.7
United States of America 2000 Health management & support workers 1237.9
United States of America 2000 Laboratory health workers 228.4
United States of America 2005 Nursing and midwifery personnel 981.49994
United States of America 2011 Other health workers 845.89996
United States of America 2010 Pharmaceutical personnel 88.1
United States of America 2011 Physicians 245.2
Uruguay 2008 Dentistry personnel density 70.1
Uruguay 2008 Health management & support workers 69.5
Uruguay 2008 Laboratory health workers 17.0
Uruguay 2008 Nursing and midwifery personnel 554.8
Uruguay 2008 Other health workers 137.0
Uruguay 2008 Pharmaceutical personnel 53.100002
Uruguay 2008 Physicians 373.6
我想确定这个国家和事业是否相同,我只会根据最近一年的情况进行过滤。
这是我的代码,但它不起作用。
b = LOAD '/nomnom' AS (country:chararray, year:int, career:chararray, density:chararray);
c = GROUP b by (country,career);
d = FOREACH c GENERATE MAX(b.year) AS val, group, $1 as max;
e = FOREACH d {
row = FILTER b BY (year == val);
GENERATE FLATTEN(row);
};
DUMP e;
答案 0 :(得分:2)
分组后(c
),按年份对分组数据进行排序,并采用最新的分组数据:
d = foreach c {
sorted = order b by year desc;
latest = limit sorted 1;
generate FLATTEN(latest);
}
dump d;