473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

rows of consecutive dates if the value is same everyday

Hi,

We are facing an issue with the JDBC query, I need help on.
I have 3 fields, UPC_ID, QTY,Date
I have to retrieve all the records for one UPC_ID whose QTY is same for last five days. The problem here is the QTY will not be inserted on sundays. When when we run the query on a Monday, we should consider the Qty for last wednesday to saturday and for monday.
I have written a query where I retrieve the data for last 6 days considering sunday to be in the middle, and group by QTY and count of the rows is>4 i retieve the data. But when i run this on saturday, It gives me a problem as, though the QTY was different on Tuesday, the count would be >4 and that record is retieved. Please help.

My query

select UPC_ID,QTY(select UPC_ID,QTY,count(1) as count rows where date>sysdate-6 group by UPC_ID, QTY)a1 group by QTY having sum(countrows)>4

which gives me a wrong output when ran on saturday.
Oct 30 '08 #1
1 3840
Pilgrim333
127 100+
Hi,

I think the following would work:

SELECT upc_id, qty
FROM table
WHERE date >= ( SELECT MIN(date)
FROM (SELECT date
FROM table
GROUP BY date
ORDER BY date DESC
)
WHERE rownum <= 5
)
This will give you all the inserted data from the last 5 inserted dates. This will work for the last 5 days if you are sure that EVERY day data will be inserted, except on sunday.

You will have to add the rest of the query yourself (getting the upc_id's with the same qty for the last 5 days) I don't know how this will perform, let me know.

Hope this will help you, otherwise let me know.

Pilgrim.
Oct 30 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Adam | last post by:
Hi, I am trying to mark consective numbers in a data set and get a count as to how many consecutive numbers exist in the a given line of data. Here is an example line: 3, 5, 7, 9, 10, 13,...
22
by: Bryan Guilliams | last post by:
I'm trying to come up with an elegant, simple way to compare two consecutive values from the same table. For instance: SELECT TOP 2 datavalues FROM myTable ORDER BY timestamp DESC That...
4
by: remote89 | last post by:
Hi experts, I have been trying to limit the table rows in the following situation, any suggestions will be appreciated. we have table called tempTb has columns id, c_id, c_name, rating, date...
15
by: plaztik8 | last post by:
Hello, Can someone please help me with a query? The table looks like this: BookedRooms =========== CustomerID RoomID BookDateID
20
by: WindAndWaves | last post by:
Hi Gurus I was wondering if you can send me in the right direction: I have a table with about 300 rows. I want to make all of them invisible and when a user enters a code in a form then make...
14
by: Jacko | last post by:
Hi guys, Say I made a SELECT statement to my sql DB that would return 50 rows that I will use a sqldatareader to access. Instead of iterating through each and every row of the datareader, I'd...
6
by: rcamarda | last post by:
Hello, I need to find students that have 4 consecutive absences. When a student is absent 4 times in a row, they can be dropped from the class. My class attendance file contains each attendance...
6
by: kilter | last post by:
Anyone know of a routine that will return the number of rows and columns in a matrix?
3
by: emeped | last post by:
I am using C#.NET 2003. Please I want to know if it is possible and how to insert the same data into 2 or more consecutive rows in a datatable column, at the same time, by a single click of a button....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.