Anda di halaman 1dari 2

SELECT *

FROM
(
SELECT CUST_GENDER , COUNT(*) AS cnt
FROM CUSTOMERS
GROUP BY CUST_GENDER
)
PIVOT
(
sum(cnt) AS sum_quantit FOR (CUSTOMERS) in('single','married')
);

SELECT *
FROM (SELECT CUST_GENDER, case
when CUST_MARITAL_STATUS = 'single' then 'single'
when Cust_marital_status = 'married' then 'married'
else 'null' end as CUST_MARITAL_STATUS
FROM CUSTOMERS
)
PIVOT (count(*) AS Gender_count FOR (CUST_MARITAL_STATUS) IN ('single' AS
single, 'married' AS married,'null' AS unknown));

select CUST_GENDER,
SUm(CASE when CUST_MARITAL_STATUS = 'single' then 1
else 0 end )as SINGle_count,
SUm(CASE when CUST_MARITAL_STATUS = 'married' then 1
else 0 end )as married_count
,SUm(CASE when CUST_MARITAL_STATUS is null then 1
else 0 end )as unknown_count
from Customers
group by Cust_gender;

select plan_table_output
from table(dbms_xplan.display('plan_table',null,'basic'));

select count(*) as count_of_single


from customers
where cust_marital_status = 'single'

Anda mungkin juga menyukai