Order of query
Hello
I have this query, but it does not correctly order DATE1 column.
SELECT NULL LINK, TO_CHAR(d, 'HH24')|| ' h.' AS date1, ROUND(MAX(v) OVER(PARTITION BY g), 2) AS valeur FROM (SELECT d, v, COUNT(v) OVER(ORDER BY d) AS g FROM (SELECT d, AVG(valeur) AS v FROM evv_st25,(SELECT TO_DATE('03/11/2014', 'DD/MM/YYYY') + (LEVEL - 1) / 24 AS d FROM DUAL CONNECT BY LEVEL <= 24) WHERE date1(+) >= d AND date1(+) < d + 1 / 24 AND clef_var(+) = 3991 GROUP BY d ORDER BY d ) )
As you can see from this screenshot, the DATE1 column is not correctly sorted as hours, days, for example on line 11, it is 06 h. and on line 12, 22 h.
I wish that the DATE1 column sorted properly as hours of the day.
Thank you.
Hi Christian,
It is a little more complex, I think.
Try this
ksdfskdg SELECT NULL AS LINK, TO_CHAR(d, 'HH24')|| ' h.' AS date1, ROUND(MAX(v) OVER(PARTITION BY g), 2) AS valeur FROM (SELECT d, v, COUNT(v) OVER(ORDER BY d) AS g FROM (SELECT d, AVG(valeur) AS v FROM evv_st25, (SELECT TO_DATE('03/11/2014', 'DD/MM/YYYY') + (LEVEL - 1) / 24 AS d FROM DUAL CONNECT BY LEVEL <= 24) WHERE date1(+) >= d AND date1(+) < d + 1 / 24 AND clef_var(+) = 3991 GROUP BY d -- ORDER BY d -- no need to sort here ) ) order by 2;
concerning
Kay
Tags: Database
Similar Questions
-
How to order a query by a column added by using QueryAddColumn()?
I have a query ("GetTotals"). I add a column it is else the query ("GetTheList") using the standard code:
< CFSET myArray = ArrayNew (1) >
< cfloop query = "GetTheList" >
< CFSET TotalJobs = GetTheList.Total >
< CFSET x = ArrayAppend (myArray, TotalJobs) >
< / cfloop >
< CFSET x = QueryAddColumn (GetTotals, "Total", "VarChar", myArray) >
< CFOUTPUT QUERY = "GetTotals" > what shows how I need.
Except for one problem: how to control the output by the added column?
Simple re-order (below) works for a column only, but not for all of them.
< cfquery name = "ResortQuery", dbtype = "query" >
SELECT *.
OF GetTotals
ORDER BY DESC totals
< / cfquery >
Any ideas are appreciated!
Not quite sure what you mean by "works for a column only, but not for all the'.»» You add more columns? Or that you're also wanting to make secondary classification, for example have ordered them totals, and then by name?
If for example your query is already ordered the name, you added your new column of totals. You should be able to:
SELECT *.
OF GetTotals
ORDER BY DESC, Name ASC totals
PS: when you use
to call functions like this, you don't have to assign them to a variable: arrayAppend returns a Boolean value, queryAddColumn returns an integer indicating the number of the new column. In most cases, these values are not used; You can simply do:
-
Error in query of the ordered result query contained CFSCRIPT in CF10
I came across a very interesting error when you perform a query of a query within a CFSCRIPT tag...
I get a result in withdrawal of a SQL Server stored procedure. This is a list of metric names (METRIC_ID) and the metric measures themselves.
I need to pull the METRIC_ID for this outcome, plans to make a JOIN on another query having display and other attributes of formatting for display in a web page.
The following code runs without error when the query is not ordered:
var displayDataQuery = new Query();
displayDataQuery.setName ("joinedQuery");
displayDataQuery.setDBType ("query");
displayDataQuery.setAttributes (qry1 = fullMetricsListQuery);
displayDataQuery.setAttributes (qry2 = arguments.cubeData);
displayDataQuery.setSQL ("SELECT METRIC_ID FROM qry2");
var tempResultSet = displayDataQuery.execute ();
var cubeMetricIDList = tempResultSet.getResult ();
When I take the same results of exact query of the same stored procedure, but it is controlled by an ORDER BY clause, this statement;
var tempResultSet = displayDataQuery.execute ();
get the following error: "value" cannot be converted to a number.» It is 2 apostrophes, meaning an empty string between 'value' and 'impossible.'
Wait, what? I want to just a list of names metrics, varchars. Why is there a conversion error...?
The error in the end pprovided back to ColdFusion10\cfusion\CustomTags\com\adobe\coldfusion\base.cfc, line 445
OK, this is where it takes an interesting twist...
Starting at line 444, in base.cfc, line 445 bolded in red:
"< cfif sqlType NEQ" "and arraylen (sqlParams) gt 0 >."
< cfloop index = "i" = "2" to = "#ArrayLen (sqlArray) #" >
< arraylen (sqlParams) of lte cfif (i-1) >
< cfqueryparam attributeCollection = "#sqlParams [i-1] #" / >
< / cfif >
#getPreserveSingleQuotes (sqlArray [i]) #.
< / cfloop >
< / cfif >
So if I understand correctly, when I have a query, unordered, copy the following code in base.cfc bed the SQL code in displayDataQuery.setSQL ("SELECT METRIC_ID FROM qry2"), but is not when the query is controlled by METRIC_ID... ?
Oh, wait... the CFDUMP when using an ordered set of data says something else...
query RESULTSET CACHING fake EXECUTIONTIME 4 SQL SELECT * FROM qry1 ORDER OF METRIC_ID, LOCATION I'm a bit confused why the same data in works set ordered, while an ordered set causes this error.
All useful suggestions or clues would be greatly appreciated!
Do you mean that the error has occurred without the order by clause?
Given that the error only occurs with one unsorted data set, I'm a bit confused why you ask this...?
I've followed your suggestion:
Run the same code, but use the cfquery instead of cfscript tag. The error persists there?
My assumption was that your suggestion is to test it against a set of ordered data because that is what caused the original error.
Unfortunately, the error occurs in the scenarios the tag and script-based.
There is absolutely no sense why this happens. The order of a set of data should have no impact on a query of a query on a column defined as varchar.
If there are null values in the other columns defined as a type of digital, big deal, the code in question does not seek to assess these columns. Still more interesting thing is why disorderly orderly vs makes a difference.
-
Hi all
This query must sort my reports in descending order, as recently happened to the employee must be displayed on the top, I tried this query in sql workshop and it shows employees in descending order, but in the reports page its been not show accordingly! It displays in a random order.select emp_id,emp_name,doj from employees order by doj desc;
Pointers?
Thanks in advanceYou do not to specify the ORDER BY in IR
1. create the IR without ORDER OF
2. run the IR
3. click on Actions - Format - sorting. Set your sort here order and apply
4. click on Action - save report and Save as default report parameterKind regards
-
Hello
Here's the example query.
with t1 as)
Select 1 as id, 'aa' as the name of double
Union
Select 2, 'a2' of the double
Union
Select 3, 'qe' from dual
Union
Select option 4, 'ee' from dual
Union
Select 5, are ' double
Union
Select 6, 'tt' from dual
Union
Select 8, 'kl' double)
SELECT id, name from t1 where id in (6,2,12,5,1)
the result obtained
ID NA
---------- --
1 aa
2 a2
5 re
TT 6
But I need results in order (as in the values clause ic (6,2,12,5,1))
ID NA
---------- --
TT 6
2 a2
5 re
1 aa
Is this possible?
Thank you
SujnanYou can, but you'll need to duplicate the data in the clause of a DECODING (or CASE) statement IN
SQL> ed Wrote file afiedt.buf 1 with t1 as ( 2 select 1 as id, 'aa' as name from dual 3 union 4 select 2, 'a2' from dual 5 union 6 select 3, 'qe' from dual 7 union 8 select 4, 'ee' from dual 9 union 10 select 5, 're' from dual 11 union 12 select 6, 'tt' from dual 13 union 14 select 8, 'kl' from dual) 15 select id,name 16 from t1 17 where id in (6,2,12,5,1) 18* order by decode( id, 6, 1, 2, 2, 12, 3, 5, 4, 1, 5 ) SQL> / ID NA ---------- -- 6 tt 2 a2 5 re 1 aa
Justin
-
I use the CMIS query to a content query:
SELECT cmis:name from cmis:document WHERE IN_TREE('/AcqUCM/IDC:Folder/687225755214001010') ORDER BY cmis:name ASC
I get an error message:
Caused by: oracle.webcenter.content.integration.cmis.query.ParseException: May 23, 2011 15:45:19 oracle.webcenter.content.integration.cmis.query.VcrExpressionSearchDelegate registerOrderBy
GRAVE: Not classifiable property: cmis:name.
How can I order my query results?
Thank you
MitchTry this:
select * from ora:t:IDC:GlobalProfile WHERE IN_TREE('/AcqUCM/IDC:Folder/687225755214001010') ORDER BY ora:p:dDocTitle ASC
or
SELECT cmis:name from cmis:document WHERE IN_TREE('/AcqUCM/IDC:Folder/687225755214001010') ORDER BY ora:p:dDocTitle ASC
One thing you can check is in the UCM metadata fields are available, but I think that dDocName and dDocTitle are available by default.
It is possible that you could meet the indexer for the AAU. This can be done in the admin cmdlets in Complutense University of MADRID. If you don't know how, I'll give you more details tomorrow when I have a server of the University Complutense of MADRID.Published by: Yannick Ongena May 23, 2011 22:29
-
Order General questioning of IEC 60870-5-104
Dear all,
I use the NI Communications toolkit to create slave IEC 60870-5-104 (station controlled).
I use s/w of Triangel microworks part and use it as the master for the same. I am able to send and receive the bulk of orders with the examples provided with the Toolkit to "C:\Program NIUninstaller Instruments\LabVIEW 2012\examples\IEC60870-5,
I am not able to find a way to capture the "questioning general command" from the server.
Can someone help me how to proceed with this.
Thank you.
Hi Frabto,
The development team has had some great insights below. I have bad informed you (sorry!) behavior, that the command general question should be processed automatically in the communication stack.
First the order of query sent to control the station may request the complete(station interrogation) or a subset (group interview) of all the data points on the control station. NEITHER 60870-5 to the command station supports the command when the control station receives an order of questioning of the station, it will reply with all the values of the data points. If the Group interrogation command, it will reply with the values of the data points that belong to the group. Users are not able to detect whether the query command is received or not, is automatically handled inside the battery, it allows users of the VI called "Set Group.vi" inside the VI polymorphic "set Property.vi" to set a point to be one of the 16 groups and you can see the usage with the example 'Interrogate information in Group.vi objects' in the folder of the example 60870-5.
You shouldn't need to do anything to respond to a command of the interrogation. The station will automatically answer. I hope that I did not cause you too much confusion on this point.
-
select level as lvl --,1 as ordered from dual connect by level <=5 union all select rownum as lvl --,2 as ordered from dual connect by level <=5
How to order the query after the UNION ALL clause in descending order
My expected results
1
2
3
4
5
5
4
3
2
1
Select * from (select level as lvl-, 1 as ordered
of the double
connect by level<>
order by 1)
Union of all the
Select * from (select rownum as -lvl 2 as he ordered
of the double
connect by level<>
order by 1 desc)
-
Hello
I created a Gantt chart and discovered a problem. Jobs don't always appear in chronological order.
I tried to order the query by date, but then the tasks don't always show next (or in the same order) on the bars to the right of the plan.
Is anyway I can order the tasks without losing the alignment with the diagram of the individual task bar?
Thanks in advance.
Hello
You have not specified what type of Gantt chart, you use: it is a project gantt chart or resource? In addition, you are dealing with hierarchical data?
Looks like you might be dealing with hierarchical data and the order in which the data are generated is cause your problem and culminating in the timeline entries being out of alignment with the datagrid control. So, without seeing the application in use, my suggestion would be to update the query to generate a hierarchical representation of your data via an START WITH... CONNECT BY question, using a syntax similar to the following:
Select the
link,
TaskName,
ID,
parent_id,
start_date,
End_date,
status
tasks _table
Start by parent_id is null
connect by parent_id = prior id
siblings arrested by start_dateIf the query is retrieving the list of tasks and then hierarchically by listing the based on parent-child association which was held in the PARENT_ID of the table column. The end result means that each parent task is listed with their tasks associated with children and sorted by START_DATE.
If this isn't answering your query, please update this thread with more information about your test scenario. Even better - if you could create a unit test on apex.oracle.com and post a link to the unit test and the syntax of the query you are using, it would be very useful.
Kind regards
Hilary
-
query: bulletin boards remove list
I want to delete record of mother/parent/one table and delete dependent records in the child tables.
For this, I would like to query for names of tables list in order (order) can I use to create delete clauses from the deepest children tables.
How to write this query?
My original query (the entrance is the name of table "List of GAMES"):
I don't know how to reproduce the query with the well known table name or the name of the system table, but this request appears in the 3rd LEVEL of depth, is column - this correct order just query "LEVEL DESC" and delete list of such order to produce?SELECT PARENT, Child, LEVEL FROM (SELECT Parent_Table.Table_Name PARENT, Child_Table.Table_Name Child FROM all_Tables Parent_Table, all_Constraints Parent_Constraint, all_Constraints Child_Constraint, all_Tables Child_Table WHERE Parent_Table.Table_Name = Parent_Constraint.Table_Name AND Parent_Constraint.Constraint_Type IN ('P', 'U') AND Child_Constraint.r_Constraint_Name = Parent_Constraint.Constraint_Name AND Child_Constraint.Constraint_Type = 'R' AND Child_Table.Table_Name = Child_Constraint.Table_Name AND Child_Table.Table_Name != Parent_Table.Table_Name AND Parent_Constraint.Constraint_Type = 'P' AND Parent_Table.Table_Name != Child_Table.Table_Name) START WITH PARENT = 'GAMELIST' CONNECT BY PRIOR Child = PARENT;
(Oracle 10g, Sun OS)Hello
Yes; If table A reference table B, then A will appear at LEVEL = n and B appears to LEVEL =(n-1), then you need to remove the lines form the table with the first top-level.
This approach does not work with cyclic dependencies, of course.
What happens in the world does that mean? Take the example of an employee (as scott.emp) table and a department table (a little, but not exactly, like scott.dept). Each emp may be assigned to a Department, so there is a foreign key in emp SEO Dept. Now imagine that each Department has (at least) a spokeman, an employee. so the dept table might have a key referening foreign emp. If this query encounters such a loop, it will trigger the "ORA-01436: CONNECT LOOP is data user" error. Assuming that you get around to it, two tables may appear LEVEL = 1 (if that is what is happening in the START WITH clause), and the other will be at LEVEL = 2, but it is meaningless, since you can not just delete rows in each table in this case.Remember that the table names are not unique. You can put the owner of the table in the SELECT and START WITH clauses. Even if all the tables are now in a single schema, or you know who are the owners of all the tables, you do not change this query than the change of these conditions.
If you create when foreign key with the ON DELETE CASCADE option, you can simply delete the parent rows, and all the children who make reference to this parent will be automatically deleted as well.
-
"Order by" instruction Dynamics
Hi guys,.
I am trying to build a dynamic sql query in java (see below)
Now what I want to do is to add a final "else" statement that would order the query based on the question of if the table contains a column named "CustomerID". There will be several tables with this column, so I want to sort those who have this column by custID. (Rather than having hundreds of other if statements for each table that has only column name). Is this possible? I've seen people using "decode", but I can't work out how to use it here.sqlStr = "Select * " + "from " + tableName if(tableName!=null){ if(tableName.equals("Table1"){ sqlStr = sqlStr.concat("order by city desc"); }else if(tableName.equals("Table2"){ sqlStr = sqlStr.concat("order by country desc"); }else if(tableName.equals("Table3"){ sqlStr = sqlStr.concat("order by price desc"); } }
Published by: ziggy 16 Sep, 2010 13:57Why you do not create your sqlStr through a procedure from tablename as an input parameter? For the satisfaction of your condition you must query the data dictionary and then generate your sqlStr.
I don't have to if you can do it in Java.
... Vivek
-
Query on the organized Table (IOT) Index sorts unnecessarily data
I created hist3 to the table as follows:
create table hist3)
reference date,
palette varchar2 (6).
Artikel varchar2 (10),
Menge number (10),
status varchar2 (4).
VARCHAR2 (20) text.
VARCHAR2 (40) data.
primary key constraint hist3_pk (reference, palette, artikel)
)
index of the Organization;
The table being an IOT, I expect that the retrieval of rows in the same order as in the primary key must be very fast.
This is true for the following query:
SQL > select * from hist3 by reference;
-----------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | 1000K | 82 M | 3432 (1) | 00:00:42 |
| 1. INDEX SCAN FULL | HIST3_PK | 1000K | 82 M | 3432 (1) | 00:00:42 |
-----------------------------------------------------------------------------
But if I add the following column of the primary key as a criterion of the order, the query becomes very slow.
SQL > select * from hist3 by reference, palette;
------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | TempSpc | Cost (% CPU). Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | 1000K | 82 M | 22523 (1) | 00:04:31 |
| 1. SORT ORDER BY | 1000K | 82 M | 200 M | 22523 (1) | 00:04:31 |
| 2. FULL RESTRICTED INDEX SCAN FAST | HIST3_PK | 1000K | 82 M | 2524 (2) | 00:00:31 |
------------------------------------------------------------------------------------------
If I look at the execution plan, I don't understand why a SORT statement should be needed, as data already take the IOT in the order requested.
Any thoughts?
ThomasThere are various ways how Oracle sorts VARCHARs.
When you create an index on a VARCHAR column, sort order is binary.
Try ' alter session set nls_sort = "BINARY" "and run your query." -
What happens if I don't know several target load order in advance?
OWB always lets user to set a load order target for mapping that has multiple targets, what should I do if I don't know in advance the target load order?
Load order sometimes target is determined by the source table (file) and change several times during execution according to the record in the source.
A set of example of the record.csv of the source file data is defined as: (insert I:, U:update, delete D)
Action, DateTime, key, name Desc
I, 71520031200, ProdABC, ABC, ABC product
I, 71520031201, CRC, ProdCDE, produces CDE
I, 71520031202, XYZ, ProdXYZ, product XYZ
U, 71620031200, ProdABC, ABC, ABC produced with option
D, 71620032300, ProdABC, ABC, ABC produced with option
I, 71720031200, ABC, ProdABC, former ProdABC reintroduced
U, 71720031201, XYZ, ProdXYZ, rename XYZ
You want to load the data into a target table as follows:
DESCRIPTION OF THE NAME OF THE KEY SRC_TIMESTA
CRC product ProdCDE CDE 71520031201
71720031201 XYZ ProdXYZ rename XYZ
ABC 71720031200, ProdABC former ProdABC reintroduced
Solution: we define three targets, one for insert, delete and update.
The order of loading for these targets are exactly the order in the file line by line, of the source, so order here are not determined, how instruct owb to load targets in the order of the records in the source?Agree with Dallan, you CAN get it works.
Your flow of source table separator which has three external groups according to your flag field and you have three targets defined by type of operation. Don't worry about the definition of an explicit load order.
For OWB to generate Code that works, on the configuration tab set:
Block size = 1
By default the operating Mode = line on
Optimize the Code checked =
Use the load order target = unchecked
Bulk processing = Code checked
Generation line Mode = onAnd the generated code SHOULD do what you want, scroll down your input in the order at a table and apply the proper functioning of this line.
Now, if OWB keeps their code generating engine constant from one version to the other is debatable. Frankly, I would like to make a remark that future updates OWB would need to re - test this map.
I should also mention that I am always wary of any implied order in a select statement, which assumes the code. It is expected that a "Select * from external_table" will bring back lines in the same order as the file. And he cursed well should!
But no one has ever seen Oracle guarantees the order of query results when it is not explicitly specified in a clause "order by"?
Me too.
And given my distaste of uncertanty and assumptionms, I would say that IF the order of processing is a neccessity then I would add a pseudo-column RECNUM to the external table definition and order it before executing by the dispatcher to ensure this order.
Mike
-
prj_id project_name created by
============================
1 orange
2 apple
3 jane Zhang
4 joe cakes
5 jason juno
Basically, I want to order the query so
(1) those who have hidden value "created by" will appear on the top and then order by project name
(2) the rest that has the value ' create by "is classified by project name first, and then 'create '.
the result I want to achieve is:
prj_id project_name created by
=============================
2 apple
1 orange
4 joe cakes
5 jason juno
3 jane Zhang
It is possible with sql query?This should work:
WITH DATA AS (SELECT 1 prj_id, 'orange' project_name FROM DUAL UNION ALL SELECT 2 prj_id, 'apple' project_name FROM DUAL ), DATA2 AS ( SELECT 3 prj_id, 'zoro' project_name, 'jane' created_by FROM DUAL UNION ALL SELECT 4 prj_id, 'cake' project_name, 'joe' created_by FROM DUAL UNION ALL SELECT 5 prj_id, 'juno' project_name, 'jason' created_by FROM DUAL ) SELECT PRJ_ID, PROJECT_NAME, NULL, 1 FROM DATA UNION ALL SELECT PRJ_ID, PROJECT_NAME, CREATED_BY, DECODE(CREATED_BY, NULL, 1, 2) FROM DATA2 ORDER BY 4,2,3
-
The above statement, I get a forrest of XML nodes in the wrong order.
I have a sequence of XML elements in a table:
[Sorry for such things ' < span span > < time > < > < span > < span > > < "-I did not find a way to remove it]
T5100 = 4, seqno = 1 T5100 = 7, seqno = 2 T5100 = 10, seqno = 3 T5100 = 13, seqno = 4 T5100 = 16, seqno = 5 T5100 = 19, seqno = 6 T5100 = 22, seqno = 7 T5100 = 25, seqno = 8 T5100 = 37, seqno = 9 T5100 = 40, seqno = 10 T5100 = 43, seqno = 11 T5100 = 46, seqno = 12 T5100 = 49, seqno = 13 T5100 = 52, seqno = 14 T5100 = 55, seqno = 15 T5100 = 73, seqno = 16 T5100 = 76, seqno = 17 T5100 = 79, seqno = 18 T5100 = 106, seqno = 19
'T5100' is an XML attribute in the node root aggregate xmltype (column) of the source (just used here as a token) table (< SEG9510 >).
'seqno' is a sequence number (column) of the same table in the source - which is used for the "order by".
However, my result xmlserialize goes like this:
<SEG9510 T5100="76"/> <SEG9510 T5100="79"/> <SEG9510 T5100="106"/> <SEG9510 T5100="4"/> <SEG9510 T5100="7"/>
In fact, items out-of-sequence (76-79-106) are always some that appear at the beginning, but to the end (see above).
And this subset located to evil itself is in order (76-79-106).
For this, I was not sure if it's because of xmlagg (...) or xmlserialize (...).
So, I picked up the 1st element of root XML result xmlagg (...) (via "excerpt") and registered separately:
<SEG9510 T5100="76"/>
So the question is on xmlagg (...).
So what is wrong here?
-Thanks a lot!
Best regards
Frank
Your ORDER BY is moved.
SELECT... ORDER BY ordering the query results. The way you wrote your query, data will be grouped by XMLAGG in no particular order and then XMLAGG results will be ordered. What you want is to classify data while aggregating. You need to add ORDER BY for XMLAGG:
Select xmlagg (... Order by...) in...
SY.
Maybe you are looking for
-
is the canon 28-135 ultrasonic objective compatible with the EOS 6 d
is the canon 28-135 ultrasonic objective compatible with the EOS 6 d
-
Can you backup specific files and I need to compress them?
original title: CAN a Backup SPECIFIC FOLDERS, AND I have TO COMPRESS somehow to of NO USE 50 DISC? CAN I SAVE SPECIFIC FOLDERS?AND SHOULD I THE COMPRESS SOMEHOW DO NOT USE OF 50 DISCS?It is using Windows Vista backup and not having not a lot of CD -
-
Please read carefully before answering. Thank you. I have a Windows Vista HP m8330f, in which the part of windows sound does not work. A little more in detail. The audio device is a realtek HD audio integrated into the map. The audio device appea
-
Win 8 on samsung ativ smart pc - touch screen problem
Hi all all of a sudden, my touch screen doesn't work - or better that partially - working: I use the s pen with no problems and even at boot I always type my password using the key, but once I'm connected, it no longer works. facts: I always say / co
-
Trying to regenerate my installation of WIN 8
I am trying to update my installation of WIN 8. I have problems of pilot (optical drive and virtual disks) and I hope that this will help with. When I try to WIN 8, it says that some files are missing, and I need to insert my media. It is a download