select * from PRO_CIDADE t where populacao = (select max(populacao) from pro_cidade) select pro_cidade.nmcidade from PRO_CIDADE where populacao = (select max(populacao) from pro_cidade) select * from PRO_CIDADE t where populacao = (select min(populacao) from pro_cidade) select pro_esta.nmestado, count(*) from pro_cidade, pro_esta where pro_cidade.cdesta = pro_esta.cdesta group by pro_esta.nmestado select pro_esta.nmestado, count(*) from pro_cidade, pro_esta -- where pro_cidade.cdesta = pro_esta.cdesta group by pro_esta.nmestado select pro_cidade.cdesta, pro_esta.nmestado, count(*) from pro_cidade, pro_esta where pro_cidade.cdesta = pro_esta.cdesta group by pro_cidade.cdesta, pro_esta.nmestado select pro_esta.nmestado, max(pro_cidade.populacao) from PRO_CIDADE, pro_esta where pro_cidade.cdesta = pro_esta.cdesta group by pro_esta.nmestado select pro_cidade.nmcidade, populacao from pro_cidade where pro_cidade.populacao in (select (populacao) from pro_cidade) union select pro_cidade.nmcidade, populacao from pro_cidade where pro_cidade.populacao is null select pro_cidade.nmcidade, pro_cidade.populacao, c.nmcidade from pro_cidade, (select pro_cidade.nmcidade, populacao from pro_cidade where pro_cidade.populacao is null) c where pro_cidade.populacao in (select (populacao) from pro_cidade) group by pro_cidade.nmcidade, pro_cidade.populacao, c.nmcidade ####TABELA TEMPORARIA - RELATÓRIOS / CÁLCULOS TEMP ##### -- Create table create global temporary table CIDADE_TEMP ( nomecidade VARCHAR2(50) ) on commit delete rows; -- Create table create global temporary table CIDADE_TEMP ( nomecidade VARCHAR2(50) ) on commit preserve rows; INSERT INTO CIDADE_TEMP(NOMECIDADE) VALUES ('GASPAR') SELECT * FROM CIDADE_TEMP ## iNSERT COM BASE EM OUTRA TABELA ## INSERT INTO CIDADE_TEMP(NOMECIDADE) (SELECT NMCIDADE FROM PRO_CIDADE) ### TABELA VIEW - ESPELHO DE DADOS ### CREATE VIEW ESTADO_CIDADE AS SELECT UPPER(PRO_ESTA.NMESTADO) ESTADO, UPPER(TRIM(PRO_CIDADE.NMCIDADE)) CIDADE FROM PRO_CIDADE, PRO_ESTA WHERE PRO_CIDADE.CDESTA = PRO_ESTA.CDESTA SELECT * FROM ESTADO_CIDADE CREATE OR REPLACE VIEW ESTADO_CIDADE AS SELECT UPPER(PRO_ESTA.NMESTADO) ESTADO, UPPER(TRIM(PRO_CIDADE.NMCIDADE)) CIDADE FROM PRO_CIDADE, PRO_ESTA WHERE PRO_CIDADE.CDESTA = PRO_ESTA.CDESTA order by estado asc, cidade asc; #### SEQUENCE #### create sequence pro_esta_seq -- botão direito view increment by 1 start with 1 maxvalue 9999999999 insert into pro_esta values (pro_esta_seq.nextval, 'MG',1,'Minas Gerais',sysdate,user,sysdate,user) commit select * from pro_esta