all days in one day, using sqlite mainly and a bit of awk
This commit is contained in:
commit
baab18ac42
|
@ -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
|
||||
|
|
@ -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 !
|
|
@ -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';
|
|
@ -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
|
|
@ -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!
|
|
@ -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
|
|
@ -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
|
||||
;
|
|
@ -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
|
Binary file not shown.
Loading…
Reference in New Issue