SELECT *
FROM (SELECT [Patient Identifier], [Operator Index], Date, Time, ROW_NUMBER() OVER (PARTITION BY [Patient Identifier], Date
ORDER BY [Patient Identifier], Date, Time) AS RowNum
FROM Complete
WHERE [Operator Index] <= 89) AS a
WHERE RowNum <= 4
UNION
SELECT *
FROM (SELECT [Patient Identifier], [Operator Index], Date, Time, ROW_NUMBER() OVER (PARTITION BY [Patient Identifier], Date
ORDER BY [Patient Identifier], Date, Time) AS RowNum
FROM Complete
WHERE [Operator Index] >= 90) AS a
WHERE RowNum <= 2
This query returns values above 90 (I need 2 of them) or values between 80 and 89 (data is already filtered for only greater >=80) and I need 4 values above 80. I only need either 2 above 90 or 4 above 80, not both, and this query returns 2 above 90, but also the values between 80 and 89. If there are already 2 above 90, I do not want any values between 80 and 89. If there are 4 above 80, I do not need any additional values. If the are two above 80 and 1 above 90, I will take all of them (max I will ever take is 4).
4 7416
Can you give me sample data to work on?
Patient Identifier Patient Initials Date Time Operator Index
0517_00003 GHV 18-Oct-06 11:48 91
0517_00003 GHV 18-Oct-06 11:50 100
0517_00004 JMH 17-Oct-06 11:41 89
0517_00004 JMH 17-Oct-06 11:50 93
0517_00004 JMH 17-Oct-06 11:52 91
0517_00004 JMH 17-Oct-06 12:00 93
0534_00003 JS 21-Nov-06 12:35 100
0534_00003 JS 21-Nov-06 12:46 100
0534_00004 ChM 20-Nov-06 10:49 100
0534_00004 ChM 20-Nov-06 10:51 100
0534_00006 JK 4-Dec-06 9:38 100
0534_00006 JK 4-Dec-06 9:47 84
0534_00006 JK 4-Dec-06 9:50 93
0534_00007 TL 29-Nov-06 9:22 98
0534_00007 TL 29-Nov-06 9:34 100
0539_00001 PGL 9-Oct-06 9:39 100
0539_00001 PGL 9-Oct-06 9:43 95
0539_00002 DWR 27-Oct-06 10:04 91
0539_00002 DWR 31-Oct-06 11:40 92
0539_00002 DWR 31-Oct-06 11:41 96
0539_00002 DWR 31-Oct-06 11:42 92
0539_00003 JmL 30-Nov-06 9:14 96
0539_00003 JmL 30-Nov-06 9:18 97
I figured it out! Thanks!
Here is the code I wrote and it is not correct although it appears to be correct at first. I was validating my data and discovered on several instances a value of 80 (something) is there instead of 90 (something).
SELECT [Patient Identifier], Date, [Operator Index], Time
FROM (SELECT ISNULL(t9.[Patient Identifier], t8.[Patient Identifier]) AS [Patient Identifier], ISNULL(t9.Date, t8.Date) AS Date, ISNULL(t9.Rows, t8.Rows)
AS Rows, c.[Operator Index], c.Time, ROW_NUMBER() OVER (PARTITION BY ISNULL(t9.[Patient Identifier], t8.[Patient Identifier]),
ISNULL(t9.Date, t8.Date)
ORDER BY c.Time) AS RowNum
FROM (SELECT [Patient Identifier], Date, 2 AS [Rows]
FROM [First Step]
WHERE [Operator Index] >= 90
GROUP BY [Patient Identifier], Date
HAVING COUNT(*) >= 2) AS t9 FULL JOIN
(SELECT [Patient Identifier], Date, 4 AS [Rows]
FROM [First Step]
WHERE [Operator Index] BETWEEN 80 AND 89
GROUP BY [Patient Identifier], Date
HAVING COUNT(*) >= 4) AS t8 ON t8.[Patient Identifier] = t9.[Patient Identifier] AND t8.Date = t9.Date INNER JOIN
[First Step] AS c ON c.[Patient Identifier] = ISNULL(t9.[Patient Identifier], t8.[Patient Identifier]) AND c.Date = ISNULL(t9.Date, t8.Date)) AS d
WHERE d .RowNum <= d .[Rows]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Robert Neville |
last post by:
I would like to add filter functionality to my database whether
through the Main form or the subform. This question may be
rudimentary, yet I have not less experience with filtering data
outside...
|
by: Brian Newman |
last post by:
I've got what is actually a triple-layer nested form. That part works
fine. I've got the first subform related by the right key field to
the main form, then I've got the second subform related to...
|
by: swilson513 |
last post by:
In Access97 I was able to have an advance filter on a form that had a
Like statement so when you applied the filter EACH time it would asked
for the criteria. In 2000 the same filter doesn't asked...
|
by: ecoulson123 |
last post by:
I am using Access 2000. I am trying to summarize numeric data from a
large database. The problem is that I need the summarization functions
to ignore "junk" data, defined in a couple ways.
...
|
by: dennishancy |
last post by:
I have a form and a subform.
One of the fields on the primary form is employee number, whose values
are in a combo box.
Here are the steps I am taking:
- I click on Filter by Form
- From...
|
by: Stinky Pete |
last post by:
Hi,
The db I'm trying to update has a report form from which all other
statistical forms and reports are selected/printed by dept, type, cost,
number etc. The report form uses a date filter to...
|
by: la.brunning |
last post by:
Hello,
I am trying to filter a Muenchian grouping I have created. I think I am
fairly close, but I am not quite sure where to apply my filter; its
been some time since I did any work with XSLT....
|
by: Barb.Richards |
last post by:
I have created an append query that pulls information from one
database, and will append the selected information into a new table.
The fields are setup like 'number' 'category' 'code' 'shares' and...
|
by: Abedin |
last post by:
I have 9 digits in form of "111020402". Then I have another 9 digits
in form of "111020403". I have 100,000 records of these two 9-digit
numbers.
I want to filter this as follows:
District:...
|
by: franc sutherland |
last post by:
Hello,
I have a report which I filter using the me.filter command in the
OnOpen event.
Me.Filter = "OrderID=" & Forms!variable_form_name!
Me.FilterOn = True
I want to be able to open that...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |