hod5783/d7.sql

22 lines
811 B
MySQL
Raw Permalink Normal View History

with clue as (select
substr(ordered,1,INSTR(ordered,' ')-1) date,
2023-01-03 23:05:32 +00:00
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 != '')
2023-01-03 23:05:32 +00:00
select *
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)
2023-01-03 23:05:32 +00:00
left join clue as cl on (cl.title = substr("desc",1,INSTR("desc",'(')-2)
and cl.color != substr("desc",INSTR("desc",'(')+1, length("desc")-INSTR("desc",'(')-1)
and cl.date = substr(ordered,1,INSTR(ordered,' ')-1)
)
where o.customerid != 8342
and title is not null
;