如何创建两列中的值重复的数据子集?

时间:2019-09-19 16:59:12

标签: sql r

我有一个包含UPDATE T SET Schedule = Mon * POWER(2,0) + Tue * POWER(2,1) + Wed * POWER(2,2) + Thu * POWER(2,3) + Fri * POWER(2,4) + Sat * POWER(2,5) + Sun * POWER(2,6) NamesDepartmentRate和其他几个字段的数据库,我想创建一个日期重复的雇员子集。例如:

EmployeeID

应该返回

"Employees" "Department" "Rate" "EmployeeID" "Date"....
Bob          HR            19.5   09151       5/1/2019
Bob          HR            19.5   09151       5/2/2019
Bill         Accounting    20     09152       5/2/2019
Bob          HR            19.5   09151       5/2/2019
John         Accounting    21     09153       5/3/2019
Bill         Accounting    20     09152       5/2/2019
Jake         HR            23     09154       5/5/2019

谢谢!

4 个答案:

答案 0 :(得分:0)

在SQL中,如果您有重复的行,则可以使用不同的子句

select distinct bNames, Department, Rate, EmployeeID
from my_table 

答案 1 :(得分:0)

这是一个整洁的解决方案。

df_doubled <- df %>% 
  group_by("Employees", "Department", "Rate", "EmployeeID", "Date") %>% 
  count() %>% 
  filter(n > 1) %>% 
  uncount(n)

答案 2 :(得分:0)

tf.cond

答案 3 :(得分:0)

您可以为此目的使用子查询:

select Employees, Department, Rate, EmployeeID, Date
from yourtable yt1
where 1 < (select count(*) from yourtable yt2 where yt1.Date = yt2.Date);