Using distinct with an order of
Hi allI'm not an expert SQL coder and I stuck with the following problem.
I have a table named Workorder that contains a set of commands. The orders including batch = 2 contain a mistake and this should be subject to new:
[ID] [WO_ID] [BATCH]
-----------------------------
1-10-2
2 10 1
3-20-2
Apparentely so it seems very simple, but when orders are represented things get complicated.
In the above query I need pickup - just - the following line:
[ID] [WO_ID] [BATCH]
-----------------------------
3-20-2
The following line must be excluded from the list:
[ID] [WO_ID] [BATCH]
-----------------------------
1-10-2
Because the WO_ID was later re-submitted successufully:
[ID] [WO_ID] [BATCH]
-----------------------------
2 10 1
So I need to fetch all work with a different one on WO_ID orders sorted by ID desc, so the separate line contains just the highest ID (the last decree submitted again).
I tried several ways, but I was not able to mix separate + order by.
Maybe it is also possible in some other ways?
Thank you very much
Frank
So you just need to wo_id, where there were No record with status = 1?
State 1 > is error, status = 1 is OK - and if there is at least one record with the State 1, this wo_id shouldn't be in the output?
select wo_id
from workorder
group by wo_id
having min(status_id) > 1
order by wo_id
The above won't give you a registration by wo_id.
And he selects only the wo_id, where the minimum value of batch is greater than 1 - in other words, there has been no record of success for this wo_id.
If your condition is that the last record of a given wo_id must have the status > 1, then do it like:
select wo_id
from workorder
group by wo_id
having min(status_id) keep (dense_rank last order by id) > 1
order by wo_id
Tags: Database
Similar Questions
-
Hello
I use Microsoft SQL Server 2014 (SP1 - CU4) (KB3106660) Enterprise Edition (64-bit) on Windows NT 6.1(Build 7601: Service Pack 1) SELECT DISTINCT A.PI_LOOKUP_CATEGORY_ID,
REPLACE (REPLACE (UPPER (A.LOOKUP_CATEGORY_NAME), ' ', '_'), '-', '_') AS CATEGORY_TECH_NAME,
A.LOOKUP_CATEGORY_NAME,
A.LOOKUP_CATEGORY_DESCR,
COUNT (B.PI_LOOKUP_CATEGORY_ID) AS USAGE_COUNT
FROM [PI_LOOKUP_CATEGORY] A LEFT OUTER JOIN B [PI_INSIGHT_COLUMN] WE
A.PI_LOOKUP_CATEGORY_ID = B.PI_LOOKUP_CATEGORY_ID
A.PI_LOOKUP_CATEGORY_ID GROUP,
REPLACE (REPLACE (UPPER (A.LOOKUP_CATEGORY_NAME), ' ', '_'), '-', '_').
A.LOOKUP_CATEGORY_NAME,
A.LOOKUP_CATEGORY_DESCR
ORDER TO REPLACE (REPLACE (UPPER (A.LOOKUP_CATEGORY_NAME), ' ', '_'), '-', '_')above request is failed with error ' ORDER BY items must appear in the select list if SELECT DISTINCT is specified. " Microsoft SQL Server (SP1 - CU4) 2014 (KB3106660)
same query works fine with older versions of SQL servers like (2008R2, or 2012)
Please let me know the resolution of this problem...
Thank you
TouriaAsk here:
-
All,
Facing a problem with the query below... "DISTINCT with Order By Clause.
His work when we take the same distinct column and order at this time where the query works. But in my case... There are a couple of b/w of joining tables... and are distinct for a column and the order is for a different table with a different column.
Please suggest me a solution for this below query column in the separate and column used for sorting are different.
SELECT DISTINCT gl_cc.segment2
OF gl_code_combinations gl_cc,.
per_all_people_f req_emp,
per_all_assignments_f req_emp_assign
WHERE req_emp.person_id = req_emp_assign.person_id
AND gl_cc.code_combination_id =
req_emp_assign.default_code_comb_id
AND req_emp.full_name = 'xyz '.
ORDER BY req_emp_assign.last_update_date DESC
Thank you
Problem will takes us to Basic!
Processing order for SELECT statements.
SQL query(Non recursive SQL) are processed in the following order
FROM clause
WHERE clause
GROUP BY clause
HAVING clause
SELECT clause
ORDER BY clause
So if you have something in the ORDER BY, but even not Fetch in SELECT it is bound to view the error.
Given THAT order will work on column projected by SELECT!
Single table query will fail also.
Select distinct ename in order by empno emp;
SQL error: ORA-01791: not a selected expression
01791 00000 - "not a selected expression.
* Cause:
* Action:
Inclusion of the req_emp_assign.last_update_date in the select column is necessary for order processing
-
Hi all
I want to use rownum with order of clause-
When I use an order clause in the select query, I get so many lines that I don't want.
I have average-i want only two first rows according to the order of.
EG. - Select employee_id, salary of the order of salary employees;
EMPLOYEE_ID, FIRST_NAME SALARY
----------- -------------------- --------
132 2100 TJ
Steven 128 2200
2200 hazelnut 136
James 127 2400
135 Ki 2400
now, I just want to see the first two lines of the output above.
any oneone please help doesSQL> SELECT * FROM (SELECT employee_id, first_name, salary FROM employees ORDER BY salary) WHERE ROWNUM < 3; 2 3 4 5 6 7 EMPLOYEE_ID FIRST_NAME SALARY ----------- -------------------- ---------- 132 TJ 2100 128 Steven 2200
-
From here to the United Kingdom, I placed an order on the site Apple.com for an iPadPro more coverage and paid with my credit card of the United Kingdom. It was a gift and I wanted it to be delivered to my brother in San Diego, the order went through fine. The cover was delivered by UPS, no problem. The iPadPro has not been delivered however the OnTrack driver said the package was delivered but the delivery note showed a false signature. Apple investigative team have been informed and a few days later a another iPadPro was actually delivered to the correct address, this time by UPS and signed for the wife of my brother... all fine - however yesterday (a few days later), a package was left (unopened) and anonymously on his doorstep so he informed Apple and they didn't know what to do! After discussion with another Member of the staff of my brother said that, because I ordered it since the United Kingdom I would receive a tag back for me to then send it to my brother so that he can return the iPadPro to Apple, they even had the nerve to tell him to take it back to an Apple store! What an absolute mess! and disgusting service - I wish that I had not bothered with online ordering, I should have transferred money to my brother instead. Of course no apologies and nowhere near a satisfactory transaction, I use Apple products since 1986 without problem at all here in the United Kingdom... pathetic.
A question to the technical support that we, your fellow users might be able to help you? In the case of contrary and youyou want just to provide feedback to Apple, this isn't the place. Apple is not read here. Use the comments link:
-
Distinction with iPhoto Albums?
I have recently converted to pictures and there is a folder called iPhoto events that has all my old iPhoto albums events. Can I just drag these albums outside of this folder and put on my list of the albums separately and use them as any other album or is there a distinction with them. I have already learned about the distinction with smart albums, which do not count when I go try to find pictures that have not been assigned to any album (it's "Album is not a ' considers not assigned to a smart receiving photo album). I'm worried about the other distinctions that are not present in the Help menu that may affect these iPhoto created albums. Thank you.
They are just like any other album albums in a folder like any other folder
LN
-
So I can pick it up at the factory using F11 with no disc setting?
So I can pick it up at the factory using F11 with no disc setting?
Hello
Recovery files are normally hidden in the Windows Explorer, so it wouldn't be a problem - the only way you can be sure that it works or not is to try it.
If you find that it does not work, you can order a set of replacement recovery disks using the link below and use them to reinstall the OS.
http://support.HP.com/us-en/document/c00810334
If you have a problem with this link, order them directly from HP.
If you live in the United States, contact HP here.
If you are in another part of the world, begin here.
Kind regards
DP - K
-
Touchpad is not in harmony with my orders.
When you use the touch pad on my laptop cursor does not move in harmony with my orders. The cursor changes into that little bar, which I think is intended for scrolling and it scrolls WAY by far to what I am Commander do. Is it possible to not have this little bar appear? Thank you
Hi lincwack,1. What is the number of brand and model of your laptop?2. when the question is is produced?3. you remember of any change to your computer before the problem?4. the problem occurs on a specific application or all applications?In the meantime, follow these steps and check.Step 1:I suggest that you enter in the website of the manufacturer of the laptop computer, download and install the latest touchpad drivers for your laptop.Updated a hardware driver that is not working properly
http://windows.microsoft.com/en-US/windows-vista/Update-a-driver-for-hardware-that-isn ' t-work properlyUpdate drivers: recommended links
http://Windows.Microsoft.com/en-us/Windows-Vista/update-drivers-recommended-linksStep 2:Start your computer in safe mode and check if the problem persists.Step 3:If the problem does not occur in safe mode, I think it could be the work of a third-party software conflict causing the issue to occur. I suggest that you put your computer in a clean boot State in order to eliminate conflicts of third party software.Note: Follow step 7 to your computer as usual.
Aziz Nadeem - Microsoft Support[If this post was helpful, please click the button "Vote as helpful" (green triangle). If it can help solve your problem, click on the button 'Propose as answer' or 'mark as answer '. [By proposing / marking a post as answer or useful you help others find the answer more quickly.]
-
Is there a change to use mediaPlayer with InvokeManager?
Hi I used mediaPlayer with InvokeManager to play streaming video
But recently the mediaPlayer is unable to read the file
Perhaps because upgrading to the new operating system
It's my job
void DetailPage::invokeMediaPlayer(QString aUrl) { InvokeManager invokeManager; InvokeRequest request; request.setTarget("sys.mediaplayer.previewer"); request.setAction("bb.action.OPEN"); request.setUri(QUrl(aUrl)); InvokeTargetReply *reply = invokeManager.invoke(request); }
When I read the documentation for the new update (release notes)
Application integration (invocation framework) - in order to adequately support extended characters, the framework of the call games has updated its treatment of URIS to enable clients and targets to better co-ordinate their use of URI. The framework of the appeal now expected valid URIS to spend in their encrypted form to allow the targets to interpret them correctly. For the file URI, handling update ensures that the frame does not change the URI and delivers them as-is. With this change, only receiving targets URIs in invocations should expect to receive coded URIs and are required to decode them.
What I need to change my code?
Previously the job very well
Thank you
Sorry, in fact there are an error on my video webservice.
So, there is nothing wrong with mediaPlayer on new SDK (10.0.9.2318)
Thank you
-
How long it takes to start using Photoshop, once the order is placed. I need to make it work...
Well, it's one and the same software, you need to worry about this.
It takes usually 24 to 48 hours for confirmation of payment.
And there is no difference between the use of the product of the tools and features, you still get the full software with all the features even in evaluation mode.
Concerning
Jitendra
-
Can I use Muse with an existing Web site?
Can I use Muse with existing websites created with the Adobe? Or can I import a site I created with Dreamweaver in Muse?
Post edited by: Corey@Adobe
You will be able to import an existing site that has been created outside of the Muse, or the site that is created when you export as HTML of Muse.
You must use the original .muse file in order to edit your site.
Post edited by: Corey@Adobe
-
Not able to use FORALL with BULKCOLLECT
Hello
I have a requirement where I have to use FORALL with BULKCOLLECT to ensure maximum performance optimization. Now, I just read that the SQL statements that can be used in FORALL are just the Inserts, deletes and updates.
In my case, I have to call a stored procedure. How can I do? Help, please.
Pseudocode:
LOOP
GET BULK calco GATHER IN v_GrantRec LIMIT v_Array_Size;
FORALL i IN 1.v_Array_Size.COUNT
Hello (v_GrantRec (i). X, v_GrantRec (i). Y);
END LOOP;
CLOSE Calc;
COMMIT;What exactly you expect it to do for you?
ForAll is designed to process batches of DML in order to avoid the change of PL/SQL to SQL context.
Has no relevance to what you're trying to do.If you don't want to call the procedure several times, you must rewrite it to there the cursor to the function, then have the function to process all the records.
Carl
-
using weblogic unit-of-order (PUA) in the osb proxy service
Hello
I have a deployed on Weblogic server JMS queue. The messages in the queue are grouped using Weblogic JMS_BEA_Unit-of-order (PUA).
Now, I have an OSB 10 g of Proxy Service that reads messages from the queue. The problem is, upon receipt of a message, acknowledgement of receipt is sent immediately, thus eliminating the message from the queue and the next with the same unit-Of-Order message is ready for processing.
But the business scenario is the first message to read, processed and then decide to recognise or not. The second message should not be interpreted, unless the previous message is processed successfully.
Can someone help with this scenario?
Thank you
Alex
Published by: user9024636 on February 11, 2010 02:57with PUA, you'll need to do the syschronous transaction.
1. make transacation enable XA
2 using the road for the sychrounous transaction
3. use the routing options, and then select mode = request-respone
4. If the Proxy service is based on the jms then you should also together WHAT JMS Transport-> Advance settings-> XA is required-> checkedKind regards
http://SOA-Street.blogspot.com -
The sql statement is
Select ename, job
from emp, dept
where emp.deptno = dep.deptno
and emp.deptno = 10
Union
Select ename, job
from emp, dept
where emp.deptno = dep.deptno
and emp.deptno = 20
the statement above using the WITH Clause
WITH dept10 AS
(select ename, job, hiredate, sal, comm, dname, emp.deptno
from emp, dept
where emp.deptno = dept.deptno
and emp.deptno = 10)
dept20 AS
(select ename, job, hiredate, sal, comm, dname, emp.deptno
from emp, dept
where emp.deptno = dept.deptno
and emp.deptno = 20)
SELECT *.
OF dept10
UNION
SELECT *.
OF dept20
Correct me if I'm wrong...
Thank youHello
SeenuGuddu wrote:
the Question is how u would provide the statement above by using the ClauseThe answer is that the question is meaningless. You will not use a WITH clause for this work.
Because you must use a WITH clause to get the same results as the first query, I think the best way would be:
WITH unnecessary_sub_query AS ( select DISTINCT ename, job -- , hiredate, sal, comm, dname,emp.deptno -- these columns are not in the original query from emp , dept where emp.deptno = dept.deptno and emp.deptno IN (10, 20) ) SELECT * FROM unnecessary_sub_query;
is this correct using Clause WITH or correct me
No, it's not ok to make queries more complex or slow they need to do.
In addition to the extra columns, it seems that the second query that you posted (the one who has a WITH clause) produces the same results as the first request. -
10.6.8 using. With Safari I can view the Apple start page. OK, using Firefox. What happens in the last 24 hours. How can I solve this?
You can solve it using only not the OS X version 10.6, Apple Safari here on out!
Over the years, there were no updating security for what be for OS X 10.6.8 Snow Leopard!
This version of Safari is obsolete and has not been safe to use for many years.
There is one more, last recommended Mozilla Firefox web browser update complete (worms) 48.0.0 that is always available, and probably will be more safe to use until the end of the year.
https://www.Mozilla.org/en-us/Firefox/desktop/
Mozilla is complete, at the end of the present in August, full support for Firefox on OS X 10.6 - 10, 8.
OR
Guaranteed ONLY (not more new web browser feature) support for an earlier version of th is permanent to Mozilla Firefox, web browser (worms. 45.0.0) through their program of Firefox ESR, (that you CAN download, install and use) which will continue to receive the support of a security update to Firefox until next April 2017 for OS X 10.6-10, 8.
You can use these versions of the ESR. Ignore the notes support educational/business.
https://www.Mozilla.org/en-us/Firefox/organizations/FAQ/
OR
See SeaMonkey.
http://www.SeaMonkey-project.org/
Good luck!
Maybe you are looking for
-
Can I access my iPhone iTunes playlist?
I music and iTunes game - I would like to play a playlist iCloud on tv from a friend. I will be able to access my playlist on its network? Thank you, Tom
-
Satellite Pro C660 - BSOD for WLANs by FN + F8
Hello! (Sorry for my bad English, but this is not my first language) I have a problem with my (Windows 7-64 bit) Satellite pro c660. When I want to activate or DΘsactiver wifi (fn + F8).I see the wifi turns on, but after 2 seconds, I got a BSOD... So
-
How can I print wireless from my laptop?
Hello I just bought a laptop, but my printer is connected to my pc in a staircase, how I set up so I can print from my wireless laptop? Thank you very much
-
How can I get the correct email address for the Australia?
How do fix this email Add. in Austraila * address email is removed from the privacy *. I tried to email this lady but they say they cannot find the e-mail address & I just got it this morning
-
Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: You have problems with programs Error messages Recent changes to your computer What you have already tried to solve the problem