我必须展示"生日"日期格式' dd.mm'来自格式' dd.mm.yy'但只有那个"生日"有超过10名员工,名为" employeeFirm"。
当我离开时:select birthday from employeeFirm;
我明白了:
01.11.73
08.09.77
01.11.65
01.11.74
(null)
(null)
01.11.85
(null)
01.11.88
01.11.65
01.11.56
01.11.77
01.11.77
(null)
01.11.77
01.11.77
....
我想以格式' dd.mm'来获取记录,在这种情况下是" 01.11"因为我们在同一天生日时有超过10名员工。
答案 0 :(得分:2)
您可以像这样使用TO_CHAR:
SELECT case when t.formated is not null
then t.formated
else to_char(s.birthday,'DD.MM.YYYY')
end as new_birthDay
FROM employeeFirm s
LEFT OUTER JOIN(SELECT TO_CHAR(birthday,'DD.MM') as formated
FROM employeeFirm
GROUP BY TO_CHAR(birthday,'DD.MM')
HAVING COUNT(*) > 10) t
ON(to_char(s.birthday,'DD.MM') = t.formated)
如果您只想在当天拥有超过10名员工的生日,那么:
SELECT TO_CHAR(birthday,'DD.MM') as formated
FROM employeeFirm
GROUP BY TO_CHAR(birthday,'DD.MM')
HAVING COUNT(*) > 10
答案 1 :(得分:1)
试试这个:
SELECT ddmm, count
FROM (
SELECT distinct Substr(Birthday,1,5) as ddmm
, Count(Birthday) OVER(PARTITION BY Substr(Birthday,1,5)) AS count
from employeeFirm
) A
where count> 10
答案 2 :(得分:0)
WITH t AS
(SELECT dob,count(*) OVER (PARTITION BY dob ORDER BY dob) counting FROM employeeFirm)
SELECT dob,
CASE WHEN counting >10
THEN to_char(dob,'DD-MM') ELSE to_char(dob,'DD-MM-YYYY')
end
FROM t;