У меня есть SQL, который может подсчитать условие (Плохо, Плохо, Хуже) за день, сгруппировать его по месяцу и отобразить следующее:
YEARS MONTHS LV COUNTVAL
----- ------ ----- --------
2009 Apr Bad 5
2009 Apr Poor 3
2009 Apr Worse 2
2009 Aug Bad 3
2009 Aug Poor 2
2009 Aug Worse 5
2009 Dec Bad 5
2009 Dec Poor 2
2009 Dec Worse 3
2009 Feb Bad 5
2009 Feb Poor 3
2009 Feb Worse 2
2009 Jan Bad 3
2009 Jan Poor 3
2009 Jan Worse 4
2009 Jul Bad 2
2009 Jul Poor 3
2009 Jul Worse 5
2009 Jun Bad 1
2009 Jun Poor 4
2009 Jun Worse 5
2009 Mar Bad 4
2009 Mar Poor 4
2009 Mar Worse 2
2009 May Bad 3
2009 May Poor 5
2009 May Worse 2
2009 Nov Bad 1
2009 Nov Poor 5
2009 Nov Worse 4
2009 Oct Bad 5
2009 Oct Poor 3
2009 Oct Worse 2
2009 Sep Bad 2
2009 Sep Poor 4
2009 Sep Worse 4
2010 Apr Bad 6
2010 Apr Poor 1
2010 Apr Worse 3
2010 Aug Bad 3
2010 Aug Poor 2
2010 Aug Worse 5
2010 Dec Bad 4
2010 Dec Poor 2
2010 Dec Worse 4
2010 Feb Bad 4
2010 Feb Poor 3
2010 Feb Worse 3
2010 Jan Bad 6
2010 Jan Poor 3
2010 Jan Worse 1
2010 Jul Bad 2
2010 Jul Poor 4
2010 Jul Worse 4
2010 Jun Bad 4
2010 Jun Poor 3
2010 Jun Worse 3
2010 Mar Bad 6
2010 Mar Poor 1
2010 Mar Worse 3
2010 May Bad 4
2010 May Worse 6
2010 Nov Bad 5
2010 Nov Poor 2
2010 Nov Worse 3
2010 Oct Bad 3
2010 Oct Poor 3
2010 Oct Worse 4
2010 Sep Bad 3
2010 Sep Poor 4
2010 Sep Worse 3
SQL, который я использую:
select years, months, lv, countVal
from
(
select years, months, lv, count (lv) OVER (PARTITION BY years,months,lv) countVal from
(
SELECT x.years, x.months, x.days, x.lv
FROM airtest,
XMLTABLE ('$d/cdata/name' passing xmldoc as "d"
COLUMNS
years integer path 'year',
months varchar(3) path 'month',
days varchar(2) path 'day',
lv varchar(5) path 'value'
) as X
group by x.years, x.months, x.days, x.lv
order by x.years, x.months, x.days
)
)
group by years, months, lv, countVal
order by years,months
На данный момент проблема в том, как изменить его, чтобы он стал в этом формате ??
YEARS MONTHS Bad Poor Worse
----- ------ ----- -------- --------
2009 Apr 5 3 2
2009 Aug 3 2 5
2009 Dec 5 2 3
.........
.........
После изменения оно станет примерно таким.
Вы можете видеть, что отдельные данные сгруппированы в строку в каждом месяце.
Спасибо за помощь !!