sql server - create sql query to fetch repeat column values within time frame -
can me query? want result of customer_id
repeats more once in 24hrs
select o.order_no, o.customer_id, o.dateordered, o.ipaddress, c.firstname, c.lastname, cd.nameoncard order_no o inner join carddata cd on o.card_id = cd.id inner join customers c on o.customer_id = c.customer_id order o.order_no desc
adding more details.. suppose order customer id xx placed on 04/23 2:30 pm , again 2nd order placed same customer id xx on same day 04/23 5:30 pm.
i want query return me customer id xx
thanks
select customer_id, cast(dateordered date) dateordered, count(*) qtde order_no group customer_id, cast(dateordered date) having count(*) > 1
to customers have orders issued after first one, use following query:
select distinct a.customer_id order_no inner join (select customer_id, min(dateordered) dateordered order_no group customer_id ) b on a.customer_id = b.customer_id , a.dateordered - b.dateordered <= 1 , a.dateordered > b.dateordered
to customers have time more 1 order issued in period less or equal 24h
select distinct a.customer_id order_no inner join order_no b on a.customer_id = b.customer_id , a.dateordered > b.dateordered , a.dateordered - b.dateordered <= 1
Comments
Post a Comment