Query type pivot without aggregation function. Transposition of the
Hi experts,Oracle 11g.
I have a table (see the sample code to reproduce), which has a date, a group and this group (determined in another query) County. I need a query of type pivot, but without aggregate functions. It's just for a view reports. I can't understand it. Thanks for your help.
CREATE TABLE temp_task
AS
SELECT TO_DATE ('15-NOV-2012') validation_date,
'GROUP 1' AS group_number,
42 AS monthly_count
FROM DUAL
UNION ALL
SELECT TO_DATE ('14-DEC-2012') validation_date,
'GROUP 1' AS group_number,
33 AS monthly_count
FROM DUAL
UNION ALL
SELECT TO_DATE ('15-NOV-2012') validation_date,
'GROUP 2' AS group_number,
10 AS monthly_count
FROM DUAL
UNION ALL
SELECT TO_DATE ('14-DEC-2012') validation_date,
'GROUP 2' AS group_number,
32 AS monthly_count
FROM DUAL
UNION ALL
SELECT TO_DATE ('15-NOV-2012') validation_date,
'GROUP 3' AS group_number,
7 AS monthly_count
FROM DUAL
UNION ALL
SELECT TO_DATE ('14-DEC-2012') validation_date,
'GROUP 3' AS group_number,
9 AS monthly_count
FROM DUAL;
Using SQL but I must return the following:VALIDATION_DATE | GROUP 1 | GROUP 2 | GROUP 3
15/11/2012. 42. 10. 7
14/12/2012 | 33. 32. 9
Hello
You should always use an aggregate function while rotating.
Even if you have really no aggregation, in other words, when what you see in the table, it's what you will get in the result set, you will have to use an aggregate function. Is there is only a value contrinuting for each cell, then you can use the MIN or MAX. It will not matter which; Since there is only 1 value, this value will be the greater of 1, and it will be also the lowest. For NUMBER of columns, you can also use SUM or AVG.
SELECT *
FROM temp_task
PIVOT ( MIN (monthly_count)
FOR group_number IN ( 'GROUP 1'
, 'GROUP 2'
, 'GROUP 3'
)
)
ORDER BY validation_date
;
Output:
VALIDATION_ 'GROUP 1' 'GROUP 2' 'GROUP 3'
----------- ---------- ---------- ----------
15-Nov-2012 42 10 7
14-Dec-2012 33 32 9
Looks like you're doing real aggregation somewhere, to get monthly_count. It would be perhaps easier and more efficient to do the swivel at this time. What is the big picture here? Post some sample data, as it is before you calculate monthly_count and desired outcomes from these data (if it is different from what you have already posted), then we'll see if we can not aggregte it and pivot it at the same time.
Tags: Database
Similar Questions
-
Hey guys,.
I'm using version 4.2.6 apex. The theme is 26.
IM also using Listener Oracle APEX.
I can print my classic report in PDF or CSV format.
But I need to export it as a .xls extension.
Report type: SQL (body of function from PL/SQL returning the SQL) query
I need is like this cause my 'where' clause type is dynamic.
Look at using this method: Tom's Blog: a non-standard export excel 2010 (.xlsx)
I do something similar for downloads to excel in my projects...
Thank you
Tony Miller
Software LuvMuffin
Ruckersville, WILL -
Pivot table result without aggregate function
Hi all
We have the following two tables:
SQL > select * from class;
CLASS_ID COURSES
---------- ----------
1 1
2 1
3 1
2 2
3 2
5 2
6 selected lines.
SQL > select * of course.
COURSE_ID
----------
1
2
The customer needs the output in the following format:
class class class class
1 1 2 3
2 2 3 5
I considered using the operator pivot tables however they require the use of an aggregate function, but there is no aggregation only required in the result here - we demand that the output as would a PivotTable?
Try this.
WITH class(CLASS_ID,COURSE) AS)
1.1 DOUBLE UNION ALL SELECT
SELECT 2.1 DUAL UNION ALL
SELECT 3.1 FROM DUAL UNION ALL
SELECT 2.2 DUAL UNION ALL
3.2 DUAL UNION ALL SELECT
SELECT DOUBLE 5.2)
SELECT * FROM)
SELECT THE COURSE
CLASS_ID,
ROW_NUMBER () OVER(PARTITION BY COURSE ORDER BY COURSE) RN
CLASS)
PIVOT (MAX (CLASS_ID) for (RN) IN (1 as CLASS1, 2 AS CLASS2, CLASS3 AS 3));
OUTPUT:
CLASS CLASS1 CLASS2 CLASS3
-------- ---------- ---------- ----------
1 1 2 3
2 2 3 5
-
Pivot / without pivot function-example
Hello
Can someone explain to me the differece between pivot and pivot function.
Concerning
SAHello
Please find below the queries for your reference. Function pivot is introduced by from 11 g. Before that, we can solve the problems with the 'breaks', 'decode' functions.
But the pivot and unpivot functions are very flexible to Oracle11g to get the line to columns and vice versa outputs.Oracle 10g
***********
Select the task,
sum (case when deptno = 30
then the sal
Another null
end) dept30
sum (case when deptno = 10
then the sal
Another null
end) dept10
sum (case when deptno = 20
then the sal
Another null
end) dept20
sum (case when deptno = 40
then the sal
Another null
end) dept40
Sum (SAL) Total_Sal
WCP
Working GroupOracle 11g
**********Select the task, dept_30, dept_10, dept_20, total_sal
de)
Select work,
DEPTNO,
SAL,
Sum (SAL) on total_sal (work partition)
WCP
)
pivot)
Sum (SAL)
to deptno in)
30 as dept_30,
10 as dept_10,
20 as dept_20));I hope that you understand the above examples...!
KPR
-
Hello
new to oracle/mark. I need to write a query that will pull the customer details and on the columns, it will have the month-year: Jan2015, Feb2015... Dec2015.
on the lines, it will contain the details of the client. the information it will provide are the categories of risk to each month.
I create a query, but it uses a function to update and is very slow. There are approximately 3000 documents. An update of column required 15 minutes or even more. so an update of column takes 15 minutes * 9 to update until September.
the best ways to manage this demand?
my query is:
UPDATE tmpRiskGrades one
SET a.feb2015 =)
Select l.risk_grade
of rep_loanportfolio l
where a.agreementno = l.agreeement_no AND l.dtuserdatetime = February 28, 2015 ")
Certainly, that looks like a pivot base for me. Assuming that dtuserdatetime is actually a date data type, something like that will not work in your version of non-recognition:
Select customer_no, agreeement_no, customer_address, loan_type region,
Max (case when dtuserdatetime = to_date (Jan 31, 2015 "," DD month yyyy ' "))
end of the era risk_grade) jan2015,.
Max (case when dtuserdatetime = to_date (February 28, 2015 "," DD month yyyy ' "))
then risk_grade end) Feb2015,
...
of rep_loanportfolio l
where loan_type = "HOME LOAN" and
account_status = 'LIVE' and
dtuserdatetime between to_date (Jan 31, 2015 "," DD month yyyy ' ") and
TO_DATE (31 Dec 2015 "," DD month yyyy ' ")
Group of customer_no, agreeement_no, customer_address, region loan_type
order of region loan_type, customer_no, agreeement_no, customer_address
If you are on 11.2 or higher, you could look at the PIVOT keyword, which is a more concise expression of the same thing.
John
-
Hello
I do a work already done by others: implementation of a Wrapper to SQLite LabVIEW, I know how to do with .NET alas I would do that c, mainly for purposes of performance and my pointer poor knowledge is kinda make me stuck.
Some information is kindly provided here:
What I want to do is just to open a connection to an SQLite database (if not existing does not, the SQLite engine will create the embedded database and the corresponding file to save the data and everything). The function to perform the operation is indicated in the page below:
It seems simple enough:
int sqlite3_open( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb /* OUT: SQLite db handle */ ); int sqlite3_open16( const void *filename, /* Database filename (UTF-16) */ sqlite3 **ppDb /* OUT: SQLite db handle */ ); int sqlite3_open_v2( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb, /* OUT: SQLite db handle */ int flags, /* Flags */ const char *zVfs /* Name of VFS module to use */ );
However, I'm struggling a bit on the following type:
sqlite3 **ppDb /* OUT: SQLite db handle */
And I'm not really sure what type to use when calling this function of LabVIEW
Any idea, I guess it's really easy, but I'm not really used to have a type which is I guess the DataInstance but as it is not clearly explicted in the C library function prototype interpreted LabVIEW (InstanceDataType is logical but not sure if) I'm not really sure what I show in the screenshot is valid or not.
My VI seems to work like a charm, but am not sure if I'm doing something wrong.
Another prototype that I have no idea on the appeal proper LabVIEW is the close function:
I would like to get this straight, usually a parameter has a name, right? but seems not:
int sqlite3_close(sqlite3*); int sqlite3_close_v2(sqlite3*);
Similarly no idea about setting up for this one... must be regarded as the free forum like the one calling this function is... but I don't send any object?
Really confusing...
sqlite3*
I might sound really stupid, but if someone could point me to a few tracks, I'd be really grateful for that.
Thank you
Ehouarn wrote:
However, I'm struggling a bit on the following type:
sqlite3 **ppDb /* OUT: SQLite db handle */
And I'm not really sure what type to use when calling this function of LabVIEW
This parameter must be an integer of size pointer, passed by the pointer. No matter whether it was signed or not signed. The SQLite library will allocate memory for you, then put a pointer to this memory in full the pointer location as you go.
Regarding the close function, you must pass the same integer pointer, but this time he passed by value (because it is referenced with a single *, not two). There is nothing wrong with the documentation by omitting the name of the parameter. For the application of a function prototype, the parameter name is without important, since everything you need to know is the type of data. How the service chooses to refer to this setting internally is irrelevant.
-
function count() throws the error in the EQL query for metric
Hello
I try to use count function in query EQL for metric bar to display the number of occurrences of a record.
When the record type does not exist, I hope that the function returns the number 0. Instead the lift function a runtime exception and the whole Bar Metric portlet fails, error no. results available. Even if the other components of the metric bar have valid results.
2013-02-21 13:03:51, 216 WARN [MetricsBarQueryProcessor] EQL the query returns no results.
2013-02-21 13:03:51, 216 ERROR [MetricsBarQueryProcessor] EQL the query returns no results.
2013-02-21 13:03:51, 216 WARN [MetricsBarResultsProcessor] no declaration is the result of process.
The EQL query I use is
BACK NUMBER_OCCURS AS SELECT COUNT (EMP_ID) AS NUMBER_OCCURS where EMP_NAME IS NOT NULL group;
I tried to use COALESCE, but it does not help.
Can someone please suggest a work around?Varkashy,
It should work...
DEFINE foo AS SELECT COUNT (1) AS NUMBER_OCCURS where EMP_NAME IS NOT NULL group;
RETURN NUMBER_OCCURS AS SELECT
COALESCE (foo []. NUMBER_OCCURS, 0) AS NUMBER_OCCURS
GROUPPatrick Rafferty
http://branchbird.comEdited by: Branchbird - Pat on February 21, 2013 05:20
-
How to get the query of the region "PL/SQL function body returns the query string"?
Hello
is it possible to get the query string from the region of type "PL/SQL function body returns the query string"?
I can get the definition of the region as a PL/SQL procedure, but I am interested in the returned query. I tried to write something like
< pre > v_return_query: = «...» » ;
: P49_QUERY: = v_return_query;
Return v_return_query; < / pre >
to save the return on hidden item P49_QUERY string, but it does not work. I get the error message: ERR-1002 cannot find the item for the "P49_QUERY" element ID in the application '4000 '.
Kind regards
PrzemekIf you need to make reference to a page element in the block then you can use this type of control to avoid having to use generic column names:
if apex_application.get_current_flow_sgid(:APP_ID) = apex_application.get_sgid then-- runtime :P9_SQL := vSQL;else-- design time null;end if;
But if all you want to do is capture the SQL debugging you can take all the references element in the block and use the insert statement (in a debug table) as I showed earlier.
Scott
-
Satellite U920T - 10G - touch screen without any function
Hello together,
I have been using the nice nice feature now for a few weeks and start to have trouble with him.
I have the problem that randomly touch screen without any function, I can touch the screen
but I want to, but without any reaction.It starts just besides the requests or anything before, I just browsing in the web site and a second to another.
If I restart the PC, everything works normally again, I still using the drivers that have been pre-installed and have no changes for the drivers so far.
Any suggestions, what could cause this problem?
Kind regards
Hello
In my opinion, a process that controls the touch screen hangs or does not answer more and as a result, you can not touch works.
Recommend reinstalling the driver of Toshiba + Toshiba UE driver page system.
If this is not enough to try the system recovery and test the device with factory settings. -
Hello!
I have a simple object type and a proecdure in which I am trying to use it to insert into another table
-object
CREATE ORREPLACETYPEmt_mtg ASOBJECT
(
ACOL NUMBER ,
BCOL NVARCHAR2 (100)
);
CREATE ORREPLACETYPEREF_MTG ASTABLEOFMt_MTG ;
-same structure as the use of sampletbl target table in the cursor query
create table tbl_MT_MTG
(
ACOL NUMBER ,
BCOL NVARCHAR2 (100)
);
-procedure
CREATE ORREPLACEINTERIORTEST_PROCEDURE1
AS
ref_cur sys_refcursor ;
REFR ref_mtg ;
BEGIN
OPEN ref_cur FOR
Select acol,
BCOL
DE sampletbl où rownum<10;
Fetch ref_cur in bulk collectintorefr;
Insert intotbl_MT_MTG(acol,bcol)selectacol,bcol fromtable(refr);
commit;
CLOSE Ref_cur;
END;
/
When I run this procedure fails with
ORA-06504: PL/SQL: return variables of the game results or the query types do not match
ORA-06512: at "TEST_PROCEDURE1", line 10
ORA-06512: at line 2
Any help on this please...
Thanks to an OLD POST below
so perfect helped me! Thank you
Tubby
After 5 years of more :-)
How to store refcursor in collection How to store refcursor in collection
-
By using the analytical function to sort without showing this column in the result.
Hello
We use the Oracle 11.2
How to use Oracle Analytics to sort the output of a query without showing this column in the result?
Here's my query:
Select distinct nvl(SRC_CHR_NM,'0') | » #'|| NVL(EXPL_SRC,'0') | » #'|| NVL(DIM_NM,'0') | » #'|| NVL(DIM_CHR_NM,'0') | » #'|| NVL(DIM_CHR_ABR,'0') | » #'||
Decode (InStr (NVL(SRC_COL_NM,'0'), 'trim ('),'1 ', Replace (NVL(SRC_COL_NM,'0'),'trim (',' trim(PRM_DTL.'), '0',' PRM_DTL.)))) » || NVL(SRC_COL_NM,'0')) AS ALLOFIT,
DIM_NM
from EXPL_CONFIG where SBJ_AREA_CD = 'PRMDTL. '
I want to use analytical to sort by DIM_NM but I do not want to show. I want to just just the ALLOFIT column to show in the output.
Something like "row_number() over (order by DIM_NM desc).
Thank you!
Hello
If you SELECT SEPARATE, then you can only ORDER OF things in the SELECT clause. (Do you really need to do SELECT DISTINCT? Often, it's just an inefficient way to remove the lines that do not need to be there at all).
Move making the SELECT DISTINCT in a subquery and make the ORDER BY (and nothing else) in the main query.
I hope that answers your question.
If this isn't the case, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
IR of type timestamp data and function group
Are there restrictions on the function group for example based on the data type.
My problem\misunderstanding is in the IR:
USING OF "GROUP BY"
I have a TIMESTAMP (columnname TM_TIME) column and I can schose in the group by clause, but not in the function section. Is there a reason why and I could make it work.
concerning
Thorsten
Published by: Fischert on 02.05.2012 03:05Sorry for my bad English I want to say, it's the data types TIME is not available in the form of columns for functions such as min and max.
the anser on metalink
-------
As you have noticed date, timestamp do not allow to use functions such as min, max, etc... in the interactive report.
Currently, these functions are supported for columns of type number.
The problem has been addressed in the development as a bug:Bug 10247814: AGGREGATE of REPORT INTERACTIVE AND GROUP BY AGGREGATE takes CHARGE ONLY ON NUMBERS
Like many, I can see it is addressed in the next version (apex 4.2). Unfortunately, we do not have a timetable for the next version.
For now, please visit the bug via My Oracle Support.
---- -
How to get the query execution time without running...?
Hello
I had one condition... as follows...
I had 3 sql statements. I need to run only sql what runtime is very less.
Can someone help me, how to get the time query and run this query without using explain plan... ?
Thank you
RajeshI can't think in any way at all to get the query execution time without running the query.
You might get an estimate ( approximation ) If you are using explain plan.
But you have governed to explain plan for a reason, so I can't help you.
Why you do not want to use don't explain plan? -
Insertion of an expiration date in a table and have messages expire without breaking functionality
I use Coldfusion 9,0,0,251028 on Windows 7 64 bit with a Microsoft Access 97 database.
The code is for an application that supports a submitted message to a shape and publishes on a different page (breakingnews.cfm). Form of the values are inserted into the table 'news' on a database, including the date that the message was sent (mes_dat) as well as the date it should expire (exp_dat).
On the database, is_current and display columns have a default value of 0.
The action of the form is new_process.cfm, which does two things:
(1) does < cfset expdate = createdate (end_year, end_month, end_day) >. End_year, end_month and end_day are the selectors to drop-down list which sets the expiration date. A problem I've had is expdate cannot be inserted by post_breaking.cfm, but only when it is put online, on my local test server there seems to be no problem.
(2) includes a model named 'post_breaking.cfm', which runs these queries:
< name cfquery = "get_init_info" datasource = "#db #" >
Select id
News
where is_current = 1
< / cfquery >< name cfquery = "update_info_1" datasource = "#db #" >
News Update
Set is_current = 0, scrollshow = 0
< / cfquery >
< cfif get_init_info.recordcount NEQ 0 >
< name cfquery = "update_info_2" datasource = "#db #" >
News Update
display value = 1
where id = #get_init_info.id #.
< / cfquery >
< / cfif >
< name cfquery = "put_in_info" datasource = "#db #" >
Insert news
(is_current, display, mes_dat, mes_tim, mes_sub, mes_text, scrollshow, exp_dat)
values
(1.0, #createodbcdate (now ()) # #createodbctime (now ()) # ' #subject # ', ' message # #', 1, #expdate #)
< / cfquery >The message then appears on breakingnews.cfm if the is_current column on the news table is 1. This is the code I inherited, so I don't know how it does, but the code allows only 5 messages both have is_current = 1.
The part I'm trying to get moving is to have a query executes loading breakingnews.cfm which checks if the exp_dat is between now() and mes_dat to is_current value 1, while retaining only 5 items with a 1 is_current.
When breakingnews.cfm is accessed, it executes these requests:
< name cfquery = "get_info" datasource = "#db #" >
Select *.
News
where
< cfif not isdefined ("id") >
is_current = 1
< cfelse >
ID = #id #.
< / cfif >
order of mes_dat /, mes_tim / / desc/desc
< / cfquery >
< name cfquery = "add_exp" datasource = "#db #" >
News UPDATE
SET is_current = 1
WHERE now() BETWEEN mes_dat AND exp_dat
< / cfquery >
< name cfquery = "remove_exp" datasource = "#db #" >
News UPDATE
SET is_current = 0
WHERE now() BETWEEN mes_dat AND exp_dat
< / cfquery >This will cause messages that have an exp_dat between now() and mes_dat to be displayed and otherwise not display on breakingnews.cfm.
However, when a new message is submitted, access to breakingnews.cfm the first time, only the newly submitted message.
If the page is refreshed, the messages that have been filtered correctly will appear under the new message, but there are now six items to display on the page when there are only five.
How can I get the exact amount of the messages and display the first time without needing a refresh?Google 'top n ms access query' and who will not be a problem.
-
Fire of process on click of the link using query type
APEX 3.2.0.0.27
I have a report region based on a qry with links. Each line has a link to separate the region on the same page. I want a process to fire (manual data select the process for the region linked) when the link is clicked. The link is displayed as a button change. I set the link for an application. How to identify the application that should fire when the user clicks on the link. I also defined a separate button named: QRY. The actual process (after submit process) it's fire is conditionial on the express request = 1 IN the expression 1 column, I entered the name of the button (QRY).
However the after submit the process is not fired.
So, how to correlate the process consisting in fires when the user clicks on the link. Do not confuse the link which is represented by a button here, but in fact I have this link button, but also a 'normal' button which bears the name of QRY. When I click on the actual button named QRY then my process is triggered. However, it did not when the user clicks on the link 'button '.
What I am doing wrong?So what you have is lines of report that can be presented in many ways, as well as the value of an other Item (Hidden)
Can think of two ways
- 1 concatenate the PK value with the request, use the PLSQL substr (substring) on demand to identify the type of demand but also to extract the value of the KP.
JavaScript: doSubmit('SAVE_#PK_COLUMN_ALIAS#');
Request: SUBSTR (: REQUEST, 1, INSTR(:REQUEST,'_')-1) and PK value is SUBSTR (: REQUEST, INSTR(:REQUEST,'_') + 1)
Then assign the item suitable in a bidding process - Another method is to assign the item directly
JavaScript: $s('
','#PK_COLUMN_ALIAS#'); doSubmit('SAVE_#DEPT_NAME#'); Replace the
with the name of the page to put element
Make sure that the item is not protected (this is the default option for the hidden items)
Maybe you are looking for
-
I continue to by clicking on my on the firefox icon and it don't is not loading. After looking through the support pages, it seems that I have to save my current profile and create a new, but you must be able to open Firefox for this.
-
I'm trying to change the serial port of the Alias names in Explorer solutions measure and when I try it says that the name is currently used on the port that does not exist. I would like to erase all the aliases and start over. Any ideas?
-
I recently installed a network storage drive to my network environments with desktop computer running windows 7, windows xp professional and windows xp home. Have this problems that even when the drive has been mapped with identification information
-
Torch of blackBerry Smartphones does not load.
I checked all the posts to see if I could solve this problem with what has been published, but nothing helped. Torch work early this am, changed the alarm time and fell asleep, when rose nothing on the screen. Tried to restart and had just the red l
-
Gadget screen appears on the home page but will not move anything to the homepage
Original title: you had to send a solution to my problem of gadget #1194371707 gadget screen happens on my home page but will not move anything on the homepage, you said you would email me a solution, but you responded never please, my case is 119437