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(sele ct UPC_ID,QTY,coun t(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.
1 3872
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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, 14
The relevant part of the script which currently checks for a
|
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 gives me the two latest values. I want to test the rate of
change of these values. If the top row is a 50% increase over the row
below it, I'll execute some special logic.
|
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
columns.
id is an identity column.
date is a datetime column, the rest are varchar datatype.
Here is the table structure with sample data,
|
by: plaztik8 |
last post by:
Hello,
Can someone please help me with a query?
The table looks like this:
BookedRooms
===========
CustomerID RoomID BookDateID
|
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 selected ones visible.
At the moment, I am doing it as follows:
www.corstorphinehouse.com/d/avail.html
| |
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 like to just iterate through,
say, rows 20 through 30.
How can one do this?
|
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 by date and whether
they were present or not. When the student has 4 consecutive value 1
(absent) for a given session and a given class the are considered to be
dropped.
If I needed to know the total number of absences, I know I could group
and...
|
by: kilter |
last post by:
Anyone know of a routine that will return the number of rows and
columns in a matrix?
|
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. Data will be from a textbox bound to the column.
Thanks.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |