Como fica esse código de MySQL em SQL (no Dbeaver com conexão com Azure)?
Eu só preciso alterar o SELECT pra funcionar no SQL
CRIAÇÃO DAS TABELAS
-- TABELA VAGAS
create table vagas (
idSensor int primary key,
idVagas varchar(5),
fkSetor int,
foreign key(fkSetor) references setor(idSetor),
descVagas varchar(20)
)auto_increment = 10;
-- TABELA DE MOVIMENTO
create table movimento (
idMovimento int primary key auto_increment,
movimentacao int, -- Alterei aqui pra por como int pq binary não tava rodando, não sei porquê
dataHora datetime,
estadia varchar(20),
fkSensor int, -- foreign key
foreign key (fkSensor) references vagas (idSensor)
);
-- INSERINDO DADOS NA TABELA
-- TABELA VAGAS
insert into vagas values
(10,'A1',1, 'Coberta'),
(11,'A2',1, 'Descobertas'),
(12,'A3',1, 'PcD'),
(13,'A4',1, 'Idosos'),
(14,'B1',2, 'Coberta'),
(15,'B2',2, 'PcD'),
(16,'B3',2, 'Descobertas'),
(17,'B4',2, 'Coberta'),
(18,'G1',3, 'Descobertas'),
(19,'G2',3, 'Idosos'),
(20,'G3',3, 'PcD'),
(21,'G4',3, 'Coberta'),
(22,'F1',4, 'Idosos'),
(23,'F2',4, 'Coberta'),
(24,'F3',4, 'PcD'),
(25,'F4',4, 'Coberta'),
(26,'A5', 1, 'Idosos'),
(27,'E1', 4, 'Idosos'),
(28,'E2', 4, 'Idosos');
-- TABELA MOVIMENTO
insert into movimento values
(null,1,'2020-05-02 15:03:00','15 min',24),
(null,0,'2020-05-02 15:18:00','15 min',24),
(null,1,'2020-06-17 13:00:00','1 Hr+',11),
(null,0,'2020-06-17 14:00:00','1 Hr+',11),
(null,1,'2020-06-17 14:10:00','45 min',11),
(null,0,'2020-06-17 14:55:00','45 min',11),
(null,1,'2020-06-17 15:43:00','30 min',15),
(null,0,'2020-06-17 16:13:00','30 min',15),
(null,0,'2020-06-17 12:14:00','1 Hr+',13),
(null,1,'2020-06-17 19:43:00','1 Hr+',13),
(null,1,'2020-05-02 07:03:00','15 min',12),
(null,0,'2020-05-02 17:18:00','15 min',12),
(null,1,'2020-05-02 02:03:00','15 min',13),
(null,0,'2020-05-02 02:18:00','15 min',13),
(null,1,'2020-05-02 19:03:00','15 min',12),
(null,0,'2020-05-02 19:18:00','15 min',12),
(null,1,'2020-05-02 19:03:00','15 min',14),
(null,0,'2020-05-02 19:18:00','15 min',14);
-- ESSE SELECT AQUI Q NÃO RODA NO SQL
SET @total = (SELECT COUNT(estadia) FROM movimento where movimentacao = 1);
SET @totalGeral = (SELECT SUM(DISTINCT(@total)) from movimento where movimentacao = 1);
SELECT -- Total aqui tem 10
CONCAT(TRUNCATE(((SUM(IF(TIME(dataHora) between '06:00:00' and '11:59:59', 1,0 ) and movimentacao = 1)/ @totalGeral) * 100),0),'%') as 'Manhã',
CONCAT(TRUNCATE(((SUM(IF(TIME(dataHora) between '12:00:00' and '18:59:59', 1,0 )and movimentacao = 1)/ @totalGeral) * 100),0),'%') as 'Tarde',
CONCAT(TRUNCATE(((SUM(IF(TIME(dataHora) between '19:00:00' and '23:59:59', 1,0 )and movimentacao = 1)/ @totalGeral) * 100),0),'%') as 'Noite',
CONCAT(TRUNCATE(((SUM(IF(TIME(dataHora) between '00:00:00' and '05:59:59', 1,0 )and movimentacao = 1)/ @totalGeral) * 100),0),'%') as 'Madrugada'
FROM movimento;
CREATE TABLE
) e alguns dados para que possamos testar diferentesqueries
e sugerir soluções?