all days in one day, using sqlite mainly and a bit of awk

This commit is contained in:
setop 2023-01-03 17:21:03 +01:00
commit baab18ac42
10 changed files with 110 additions and 0 deletions

22
d1.awk Normal file
View File

@ -0,0 +1,22 @@
function toT9(s){
F = "abcdefghijklmnopqrstuvwxyz"
T = "22233344455566677778889999"
split(tolower(s),S,"");
r = ""
for (i=1;i<=length(S);i++) {
j = index(F,S[i])
r = r substr(T,j,1)
}
return r
}
{
split($1,N," ")
lastname = N[length(N)]
t9 = toT9(lastname)
phone = $2
gsub("[-]","",phone)
}
t9 == phone
# sqlite3 noahs.sqlite 'select name, phone from customers' | awk -F\| -f d1.awk

7
d2.sql Normal file
View File

@ -0,0 +1,7 @@
select *, substr(c.name,1,1) f, SUBSTR(c.name, INSTR(c.name, ' ')+1,1) l from orders as o
left join orders_items as oi on (oi.orderid = o.orderid)
left join customers as c on (o.customerid = c.customerid)
where oi.sku in (select sku from products where desc like '%bagel%')
and f == 'J'
and l == 'D';
-- call them all !

7
d3.sql Normal file
View File

@ -0,0 +1,7 @@
select * from customers WHERE
((birthdate >= '1946-03-21' and birthdate <= '1946-04-19')
or (birthdate >= '1958-03-21' and birthdate <= '1958-04-19')
or (birthdate >= '1970-03-21' and birthdate <= '1970-04-19')
or (birthdate >= '1982-03-21' and birthdate <= '1982-04-19')
or (birthdate >= '1994-03-21' and birthdate <= '1994-04-19'))
and citystatezip = 'South Ozone Park, NY 11420';

14
d4.sql Normal file
View File

@ -0,0 +1,14 @@
select count(orderid) c, name, phone from (
select *,
SUBSTR(o.ordered, INSTR(o.ordered, ' ')+1) d,
SUBSTR(o.shipped, INSTR(o.shipped, ' ')+1) s
from orders as o
left join customers as c on (o.customerid = c.customerid)
where d >= '04:00:00'
and d <= '05:00:00'
and s >= '04:00:00'
and s <= '05:00:00'
)
group by name, phone
order by c desc
-- pick the first one

7
d5.sql Normal file
View File

@ -0,0 +1,7 @@
select *, substr(c.name,1,1) f, SUBSTR(c.name, INSTR(c.name, ' ')+1,1) l from orders as o
left join orders_items as oi on (oi.orderid = o.orderid)
left join customers as c on (o.customerid = c.customerid)
where oi.sku in (select sku from products where desc like '%cat food%')
and citystatezip like 'Queens Village%'
order by phone;
-- there is only one woman!

10
d6.sql Normal file
View File

@ -0,0 +1,10 @@
-- had to fix column type for order_items/orderid from txt to int, else, was damned too slow
with sales as (select * from orders_items as oi
left join products as p on (oi.sku = p.sku)
where oi.unit_price < p.wholesale_cost)
select c.*, count(o.customerid) c from sales as s
left join orders as o on (o.orderid = s.orderid)
left join customers as c on (c.customerid = o.customerid)
group by o.customerid
order by c desc
-- pick first one

24
d7.sql Normal file
View File

@ -0,0 +1,24 @@
with clue as (select
substr(ordered,1,INSTR(ordered,' ')-1) date,
substr(desc,1,INSTR(desc,'(')-2) title,
substr(desc,INSTR(desc,'(')+1, length(desc)-INSTR(desc,'(')-1) color
from orders_items as oi
left join orders as o on (o.orderid = oi.orderid)
left join products as p on (p.sku = oi.sku)
where o.customerid = 8342
and title != '')
select *,
substr(ordered,1,INSTR(ordered,' ')-1) zdate,
substr(desc,1,INSTR(desc,'(')-2) ztitle,
substr(desc,INSTR(desc,'(')+1, length(desc)-INSTR(desc,'(')-1) zcolor
from orders_items as oi
left join orders as o on (o.orderid = oi.orderid)
left join customers as c on (c.customerid = o.customerid)
left join products as p on (p.sku = oi.sku)
left join clue as cl on (cl.title = ztitle
and cl.color != zcolor
and cl.date = zdate
)
where o.customerid != 8342
and title is not null
;

9
d8.sql Normal file
View File

@ -0,0 +1,9 @@
select count(*) c , phone
from orders_items as oi
left join orders as o on (o.orderid = oi.orderid)
left join customers as c on (c.customerid = o.customerid)
left join products as p on (p.sku = oi.sku)
where p.desc like 'Noah%'
group by o.customerid, c.phone
order by c desc limit 12
-- pick first one

BIN
noahs.sql.zst Normal file

Binary file not shown.

10
stats.txt Normal file
View File

@ -0,0 +1,10 @@
Puzzle Solve Time # Attempts
0 5 minutes 2
1 32 minutes 1
2 25 minutes 16
3 13 minutes 1
4 13 minutes 1
5 5 minutes 1
6 83 minutes 1
7 2 hours 20
8 8 minutes 1