SQL Query problem

P

Pradeep

I have a table like below

Date, Qty
1-Jan, 10
2-Jan, 10
3-Jan, 20
4-Jan, 10

I want to write a query to display

Date_interval, qty
1-Jan to 2-jan, 10
3-Jan to 3-jan, 20
4-jan to 4-jan, 10 <-- seperate row for 4-jan even though the Qty is
same

I tried by grouping on Qty from which I get

Qty, Min(date),Max(date)
10, 1-Jan, 4-jan
20, 2-Jan, 2-jan <-- no seperate row for 4-jan

Please help me in getting that extra row of 4-jan

Thanks
Pradeep
 
J

John W. Vinson

I have a table like below

Date, Qty
1-Jan, 10
2-Jan, 10
3-Jan, 20
4-Jan, 10

I want to write a query to display

Date_interval, qty
1-Jan to 2-jan, 10
3-Jan to 3-jan, 20
4-jan to 4-jan, 10 <-- seperate row for 4-jan even though the Qty is
same

I tried by grouping on Qty from which I get

Qty, Min(date),Max(date)
10, 1-Jan, 4-jan
20, 2-Jan, 2-jan <-- no seperate row for 4-jan

Please help me in getting that extra row of 4-jan

Thanks
Pradeep

I don't understand the logic here, Pradeep. Why does 4 Jan qualify for a
separate row? What is the "trigger" for going to a new row - a change in Qty,
or what?

John W. Vinson [MVP]
 
P

Pradeep

I don't understand the logic here, Pradeep. Why does 4 Jan qualify for a
separate row? What is the "trigger" for going to a new row - a change in Qty,
or what?

John W. Vinson [MVP]- Hide quoted text -

- Show quoted text -

The trigger to this request is that a letter is to be printed, the
contents of which should be,
Date Del
1-Jan to 2-jan 10
3-Jan to 3-Jan 20
4-jan to 4-Jan 10

i.e. any break in the del. qty has to be seperate. If i group on qty i
get

Date Del
1-Jan to 4-jan 10
3-Jan to 3-Jan 20

Above is confusing for the party to which the letter needs to be sent.

I hope my request is logical. I can do this with VBA (by populating a
dummy table) but just wanted to check whether a SQL query can be
written for this.

Thanks

Pradeep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top