Commit 2c607208 by Joel Florentin

join y calculadora

parent 1f00e1ef
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
</head>
<body>
<p id="screen-anterior"></p>
<input type="text" id="screen">
<table>
<tr>
<td class="tecla">7</td> <td class="tecla">8</td> <td class="tecla">9</td> <td class="tecla">+</td>
</tr>
<tr>
<td class="tecla">4</td> <td class="tecla">5</td> <td class="tecla">6</td> <td class="tecla">-</td>
</tr>
<tr>
<td class="tecla">1</td> <td class="tecla">2</td> <td class="tecla">3</td> <td class="tecla">*</td>
</tr>
<tr>
<td class="tecla">00</td> <td class="tecla">0</td> <td class="tecla">.</td> <td class="tecla">=</td>
</tr>
</table>
</body>
<script src='main.js'></script>
</html>
\ No newline at end of file
select distinct c.customer_id,c.first_name from customer as c right join rental as r on c.customer_id = r.customer_id;
select c.customer_id,c.first_name,f.title
from customer as c right join rental as r on c.customer_id = r.customer_id
right join payment as p on r.rental_id=p.rental_id
left join inventory as i on r.inventory_id=i.inventory_id
left join film as f on i.film_id=f.film_id
where p.payment_date<'2007-02-15';
select count(c.category_id) cantidad,c.name
from rental as r
left join inventory as i on r.inventory_id=i.inventory_id
left join film as f on i.film_id=f.film_id
left join film_category as fc on f.film_id=fc.film_id
left join category as c on c.category_id=fc.category_id
group by c.category_id
order by cantidad desc limit 5
;
select count(c.category_id) cantidad,c.name,cu.customer_id
from rental as r
left join customer as cu on r.customer_id = cu.customer_id
left join inventory as i on r.inventory_id=i.inventory_id
left join film as f on i.film_id=f.film_id
left join film_category as fc on f.film_id=fc.film_id
left join category as c on c.category_id=fc.category_id
group by (c.category_id,cu.customer_id)
order by cu.customer_id,cantidad desc
;
select cantidad, nom from (select count(l.name) cantidad, l.name nom
from rental as r
left join inventory as i on r.inventory_id=i.inventory_id
left join film as f on i.film_id=f.film_id
left join language as l on f.language_id=l.language_id
group by l.language_id ) as sq order by cantidad desc limit 1
;
select count(r.rental_id) cantidad, s.staff_id, s.first_name
from rental as r
left join payment as p on r.rental_id=p.rental_id
right join staff as s on p.staff_id=s.staff_id
group by s.staff_id
;
select count(a.actor_id) cantidad,a.first_name
from rental as r
left join inventory as i on r.inventory_id=i.inventory_id
left join film as f on i.film_id=f.film_id
right join film_actor as fa on f.film_id=fa.film_id
right join actor as a on a.actor_id=fa.actor_id
group by a.actor_id
order by cantidad desc limit 1
;
select count(c.customer_id) cantidad,c.first_name
from rental as r
left join customer as c on c.customer_id=r.customer_id
group by c.customer_id order by cantidad desc limit 1
;
\ No newline at end of file
const teclas = document.querySelectorAll('.tecla');
var screen = document.getElementById("screen");
var screenAnterior = document.getElementById("screen-anterior");
var entrada_anterior;
var dot_posible = true;
var escribir = function(event) {
let contenido = event.target.innerHTML;
switch (getTipo(contenido)) {
case "num":
switch (getTipo(entrada_anterior)) {
case "num":
screen.value = Number(screen.value + contenido)
break;
case "op":
screen.value = contenido
break;
case "dot":
screen.value = Number(screen.value + contenido)
break;
case "eq":
screen.value = contenido
screenAnterior.innerHTML = ""
break;
default:
break;
}
break;
case "op": case "eq":
let ls = screenAnterior.innerHTML.length-1;
if(screen.value.length==0 && screenAnterior.innerHTML.length==0) return;
switch (getTipo(entrada_anterior)) {
case "num": case "dot":
if(esOperador(screenAnterior.innerHTML[ls])){
let a = screenAnterior.innerHTML.substring(0,ls);
let b = screen.value
screen.value = operar(Number(a),Number(b),screenAnterior.innerHTML[ls])
if (getTipo(contenido)=="eq") {
screenAnterior.innerHTML += b + contenido;
} else {
screenAnterior.innerHTML = screen.value + contenido;
}
}
else{
screenAnterior.innerHTML = Number(screen.value) + contenido;
}
break;
case "op":
screenAnterior.innerHTML = screenAnterior.innerHTML.substring(0,ls) + contenido;
break;
case "eq":
screenAnterior.innerHTML = Number(screen.value) + contenido;
default:
break;
}
dot_posible = true;
break;
case "dot":
if(dot_posible){
switch (getTipo(entrada_anterior)) {
case "num":
dot_posible = false;
screen.value = screen.value + contenido;
break;
default:
break;
}
}
break;
default:
break;
}
entrada_anterior = contenido;
};
function esNumero(valor){
return !isNaN(Number(valor))
}
function esOperador(valor){
switch (valor) {
case "+": case "-": case "/": case "*":
return true;
default:
return false;
}
}
function getTipo(valor){
if(esNumero(valor)) return "num";
if(esOperador(valor)) return "op";
if(valor=="=") return "eq";
if(valor==".") return "dot";
}
function operar(a,b,op){
switch (op) {
case "+":
return a + b;
case "-":
return a - b;
case "/":
return a / b;
case "*":
return a * b;
}
}
teclas.forEach(el => el.addEventListener('click', escribir));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment