Hey!
I've got this question that I built a couple of years ago that I've been using fine since then up until today. Now it's giving an error and no changes were made to the syntax, so I don't know what happened.
Any insight would be much appreciated.
with first_order as (
select
client_id,
status,
service_id,
min(starttime) as first_time
from
tb_orders
where
starttime >= '2005-01-01' and status !=0 and status !=-1 and status !=-2 and service_id !=22 and service_id !=480 and service_id !=540 and service_id !=1503 and service_id !=895 and service_id !=896 and service_id !=1575 and service_id !=1604 and service_id !=1605 and service_id !=1065 and service_id !=1066 and service_id !=1067 and service_id !=1144 and service_id !=1727 and service_id !=1211 and service_id !=1212 and service_id !=1382 and service_id !=1427 and service_id !=1501 and service_id !=1431 and service_id !=1429 and service_id !=1500 and service_id !=1432 and service_id !=1502 and service_id !=1430 and service_id !=1499 and service_id !=1433 and service_id !=1434 and service_id !=1435 and service_id !=1527 and service_id !=1728 and service_id !=1865 and service_id !=1866 and service_id !=1867 and service_id !=1868 and service_id !=1869 and service_id !=1870 and service_id !=1871 and service_id !=1647 and service_id !=1680 and service_id !=1681 and service_id !=1682 and service_id !=1683 and service_id !=1708 and service_id !=1709
group by client_id)
select client_id as client_id, first_time as first_order_date, MONTH(first_time) as first_month
from first_order group by client_id
