我正在学习sql,我有这句话:
select owner, object_name, object_id, object_type, status, last_ddl_time
from dba_objects;
向我展示所有对象,但是我想要类似的东西:
谢谢。
答案 0 :(得分:0)
使用条件聚合:
SELECT
owner,
SUM(DECODE(object_type, 'TABLE', 1, 0)) "Tables #",
SUM(DECODE(object_type, 'VIEW', 1, 0)) "View #",
SUM(DECODE(object_type, 'TRIGGER', 1, 0)) "Triggers #",
SUM(CASE WHEN object_type = 'TRIGGER' AND status = 'INVALID' THEN 1 ELSE 0 END) "Invalid Triggers #"
FROM dba_objects
GROUP BY owner