SELECT extractValue(value(t),'value') val, extractValue(value(t),'value/@id') attr
FROM TABLE(XMLSequence(XMLType('<form><value id="1">first</value><value id="2">second</value></form>').extract('form/value'))) t;
select t1.metric_type, t1.state, (t2.date_change - t1.date_change) as diff
from
(
select rownum as n, metric_type, state, date_change
from
(
select *
from someTable
order by metric_type, date_change
)) t1
left join (select rownum as n, metric_type, state, date_change
from
(
select *
from someTable
order by metric_type, date_change
)) t2 on (t1.n = t2.n+1 and t1.metric_type = t2.metric_type)
SELECT product_id
FROM PropertyPivot
WHERE property_id IN (...) AND option_id IN (...)
GROUP BY product_id
HAVING count(*) = количество параметров поиска
CREATE TABLE db_person
(
id integer,
stat integer
);
CREATE TABLE db_person_fio
(
id_person integer,
dr date,
w integer
);
CREATE TABLE db_person_ages
(
age integer
);
INSERT INTO db_person_ages(age) VALUES (0);
INSERT INTO db_person_ages(age) VALUES (1);
INSERT INTO db_person_ages(age) VALUES (2);
INSERT INTO db_person_ages(age) VALUES (3);
INSERT INTO db_person_ages(age) VALUES (4);
INSERT INTO db_person_ages(age) VALUES (5);
INSERT INTO db_person_ages(age) VALUES (6);
INSERT INTO db_person_ages(age) VALUES (7);
INSERT INTO db_person_ages(age) VALUES (8);
INSERT INTO db_person_ages(age) VALUES (9);
INSERT INTO db_person_ages(age) VALUES (10);
SELECT CONCAT(age*11,'-',age*11+10) as descr,
IFNULL(man,0) as man,
IFNULL(woman,0) as woman
FROM db_person_ages ages
LEFT JOIN
(
SELECT FLOOR(timestampdiff(YEAR,f.dr,CURRENT_DATE)/11) as diff,
SUM(CASE WHEN f.w=1 THEN 1 ELSE 0 END) as man,
SUM(CASE WHEN f.w=0 THEN 1 ELSE 0 END) as woman
FROM db_person p, db_person_fio f
WHERE p.id = f.id_person
AND p.stat>0
GROUP BY 1
) t ON ages.age = t.diff