Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL Query

$
0
0

I'm trying to use an SQL query to find parts that have three or more orders in a week's timeframe. The weeks would be as follows: 9/2/13-9/8/13, 9/9/13-9/15/13, 9/16/13-9/22/13, and so on. I want the query to display the results according to the weekly timeframe. This is what I have so far.

select partid=i.partid, partdescription, count(partorderid) as NumberOfPartOrders

from part i

join partorder j

on i.partid = j.partid

where ordersubmitted between '09/02/13' and '09/08/13''

or ordersubmitted between '09/09/13' and '09/15/13'

group by i.partid, partdescription

having count(partorderid) > 2

It works fine for a single ordersubmitted range, but when I use multiple ranges it looks at 3 or more orders between 09/02 and 09/15. I want 3 or more orders listed between 09/02-09/08 and 3 or more orders listed between 09/09 and 09/15.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>