Analytics/aggregate sql query development
Hello
I need convert the input as data below:
as the value of category chnages, the sum must be made according to the date values.
Date | Number | CODE | CATEGORY | VALUE |
17/10/2014 11:30 | 07999999999 | IH1111 | A | 100 |
17/10/2014 12:30 | 07999999999 | IH1111 | A |
200
17/10/2014 13:00
07999999999
IH1111
A
20
17/10/2014 13:30
07999999999
IH1111
B
50
17/10/2014 14:00
07999999999
IH1111
B
100
17/10/2014 14:30
07999999999
IH1111
A
30
17/10/2014-15:00
07999999999
IH1111
C
30
17/10/2014-15:30
07999999999
IH1111
C
30
17/10/2014-16:30
07999999999
IH1111
A
30
17/10/2014-17:30
07999999999
IH1111
A
30
17/10/2014-18:30
07999999999
IH1111
B
30
17/10/2014-19:30
07999999999
IH1111
B
30
data output:
17/10/2014 11:30 | 07999999999 | IH1111 | A | 320 |
17/10/2014 13:30 | 07999999999 | IH1111 | B | 150 |
17/10/2014 14:30 | 07999999999 |
IH1111
A
30
17/10/2014-15:00
07999999999
IH1111
C
60
17/10/2014-16:30
07999999999
IH1111
A
60
17/10/2014-18:30
07999999999
IH1111
B
60
Could you please help me build the query.
Thanks in advance.
Try the below...
SELECT p_date
p_num,
code,
category,
sum_val
Of
(SELECT p_date,
p_num,
code,
category,
MySQL OVER (PARTITION BY rn3) sum_val,
ROW_NUMBER() over (PARTITION BY rn3 ORDER BY p_date) rn4
Of
(SELECT p_date,
p_num,
code,
category,
value,
ROW_NUMBER() over (ORDER BY p_date) - ROW_NUMBER() over (PARTITION BY p_num, CategoryID ORDER BY p_date) rn3
OF test_tab
)
)
WHERE the rn4 = 1
ORDER BY p_date;
OUTPUT:-
=======
17/10/2014 11:30 7999999999 IH1111 HAS 320
17/10/2014 13:30 7999999999 IH1111 B 150
17/10/2014 14:30 7999999999 IH1111 HAS 30
17/10/2014-15:00, 7999999999 IH1111 C 60
17/10/2014 16:30 7999999999 60 IH1111
17/10/2014 18:30 7999999999 IH1111 B 60
Thank you
Ann
Tags: Database
Similar Questions
-
SQL query simple SQL Developer takes, the wizzard of XE does not work
Hello everyone
I wrote this simple query that developer SQL works well, but when I try to run a report based on this sql query, it tells me invalid sql statement. It's true, maybe it's not valid because this IF clause in there... but Developer SQL seems to be very tolerant or includes more...
I wrote this is because obviously if there is no Boss, ie = 0 then I would get an error when it division by 0, so I put that 0 just for selecting the right
If count (bosses) > 0
Select company, zip code.
sum (Boss/staff)
assessment
Group of company, zip code
Thank you very much
AlvaroOk. This should work:
Select company, zip code.
-case when count (staff)! = 0 here end sum (Boss/staff)
assessment
Group of company, zip codeIf this does not work, could you please explain, how your table looks like?
-
Clarification of the SQL query in 2 day + Guide APEX
I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).
The code is:
SELECT d.DEPARTMENT_ID,
d.DEPARTMENT_NAME,
(select count (*) from oehr_employees where department_id = d.department_id)
"Number of employees", he said.
substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',
c.COUNTRY_NAME 'place '.
OEHR_DEPARTMENTS d,
E OEHR_EMPLOYEES
OEHR_LOCATIONS l,
C OEHR_COUNTRIES
WHERE d.LOCATION_ID = l.LOCATION_ID
AND l.COUNTRY_ID = c.COUNTRY_ID
AND e.department_id = d.DEPARTMENT_ID
AND d.manager_id = e.employee_id
AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)
I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.
What does this string? This code simply checking that d.department_name isn't NA?
I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.
Thank you.
2899145 wrote:
Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.
In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report
page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.
for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.
However, given that the document is a guide for the development of the APEX, I guess the command:
AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0
done something valuable, and I do not recognize what is exactly the value.
From a practical point of view why would I need to include this conditional statement? Which only added to the application?
Looking at the guide in question, it is clear that the
AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.
If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...
-
Pool pane there problem with long sql query?
Hello
I use Jdeveloper 11.1.2.2.0
In the application I'm developing, there is a long sql query to call (it's a function from a package, which may take a few minutes to run) and I want to display a progress bar for the user.
The progress bar component is a "progress indicator" and the percentage of achivement is refreshed by a component 'pool' with 1-second interval.
The two components are connected in a javabean.
The function with the sql query is the javabean too.
To run the sql query that is long on background I am calling from a thread, and the pool component get the advancement of the percentage of a pipe filled with the sql function.
If the function to run is just a long loop of java operations the progress bar works fine, but if I put my long sql query instead, stop listener pool should be performed to stop long, s sql queryo progress are updated only at the end of the long sql query.
You have any ideas?
Thank you
Thanks for your replies. Unfortunately, it was not the solution to my case, sql procedures to block the entire application while ADF awaits them at the end...
To solve my problem, I finally used a PL SQL Job to call my sql procedure (dbms_job.submit).
The application is released right after the call and the component of the pool is not more secure!
Kind regards
Yann
-
Dynamic SQL query in the DB adapter
Hello
I want to use the following custom SQL query in the DB adapter:
SELECT EMP_ID, EMP_NAME, EMP_LOCATION FROM EMP WHERE EMP_ID IN (#iNPUT_PARAMETER)
the problem I'm facing is that I don't know at the time of the development that EMP_ID how much will be passed to the process so that I can not use the input parameter specific number. I cannot use it IN the query within which statement I concatenate all the EMP_ID separated by comma and passed under INPUT_PARAMETER, but when running, he read the full concatenated string as a single string rather than identify them as a list of different: with comma separation. could someone help me in this case
Thank you
SunilUse the following query with two parameters. Build the string with delimiter when running and pass this string and delimiter to query... (in this example, the input value would be the same for both Delimiter1 and Delimiter2.)
Select * from EMP WHERE deptno IN (SELECT SUBSTR (STRING_TO_TOKENIZE, DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1), INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL)-DECODE (LEVEL, 1, 1, INSTR (STRING_TO_TOKENIZE, SEPARATOR, 1, LEVEL-1) + 1)) FROM (SELECT #StringToTokenizer | #Delimiter1 AS STRING_TO_TOKENIZE, #Delimiter2 AS DELIMITER FROM DUAL) CONNECT BY INSTR (STRING_TO_TOKENIZE SEPARATOR) ((, 1, LEVEL) > 0)
Thank you
-Sreeny -
Any difference between the separate function and aggregation in sql query cost?
Hello
I've run many models sql stmts - such as:
one) using a single table
(b) using the two tables, using simple joins or outer joins
but I didn't notice a difference in sql stmts in cost and implementation plan...
In any case, my colleague insists on only using the aggregate function is less expensive compared to
separate... (something I've not confirmed, that is why I believe that they are exactly the same...)
For the situation described above under 1 sql... We could for example use
select distinct deptno
from empselect count(*), deptno
from emp
group by deptnoselect distinct owner, object_type from all_objects
select count(*), owner, object_type from all_objects
Have you ever found no difference between the two...?
group by owner, object_type
Note: I use Ora DB 10g v2.
Thank you
SIMAlexandre Gelin says:
function separate and aggregation are for different uses and can give the same result, but if you use the aggregate function to get the separate records, it will be expensive...really? I find them almost identical to 11g. Actually GROUP BY is almost always more fast for me in the old days.
article about this askTom Re: any difference between the separate function and aggregation in sql query cost?
This applies mainly to the older oracle versions http://www.oracle.com/technology/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf -
Hello
I post this question for clarification. I have a report that is based on a SQL query area.
Place automatically APEX sql in the tables, all THE results of a query if it is in a region of report? Or y at - it a step that the developer must do to retrieve the columns of the sql query in a table.
I'm working with checkboxes, and I read up on top of the api APEX_APPLICATION. This part is still unclear.
Your comments would be appreciated!
KeishaHi Keisha,
You should have a read of: [http://download-uk.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/check_box.htm#CHDHFACG] that explains the use of checkboxes on the reports.
I guess the 'picture' you refer to are APEX_APPLICATION. G_F01 up APEX_APPLICATION. Paintings of G_F50? If so, they are built when you submit the page and are based on elements with attributes of 'name' of 'f01' up to 'f50' in the HTML tags. You don't need to do anything beforehand to create these, which is done automatically for you by the Apex. But, notes, however, that only the checked boxes are presented with a page - so if your username is checked, say, 3 of the 10 boxes, table will contain only 3 points not 10 (with each element of the table that contains the attribute 'value' of a checkbox).
Andy
-
Failed to parse the SQL query by user
Hi all
in my application, I have a piece of text with a button "submit". In this article, I type a name and a report after the element region show me the result (s). This works for all my users (> 2000) perfectly, but that users become an error in the area of the report:
Failed to parse the SQL query:
ORA-01403: no data found
We try this with the same searchstring on the same computer/browser. If I connected the result is ok, if the logged on user, the error message appears. If I try this on the user's computer with me connected, ok result. If the user try this on another pc, error results.
I have a production and a developer workspace. In the developer workspace the user can try this perfectly without errors. That in the space of productive work, clear the error.
The SQL-Select in the ist verry simple reprirt:
Select id
name
raum
table
where instr (upper (name), upper (:P60_SEARCH)) > 0
However, all users can use this search box with report perfectly, only this one user has the error. There is no restrictions on this point or a State.
Can someone help me?Hi Carsten,
I don't think that there is a way to do it.
Could you please mark the correct and useful answers in this thread? Otherwise I'll never get near Andy ;) :)
Denes Kubicek
------------------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
------------------------------------------------------------------------------ -
Œuvres SQL query to MS SQL Server 2008, but not when you use the database kit
I have this SQL query:
DECLARE TABLE (@DataTypeTable)
Name varchar (128).
TypeID INT)-Add comma delimeted type data in the temporary table names
INSERT INTO @DataTypeTable (name)
SELECT * from WhatWeShouldDoRead.func_Split (@DataTypeTrimmed, ',')SELECT the name OF @DataTypeTable
That takes a comma delimited by the string and returns the string as a table. It works correctly in Microsoft SQL Server Management Studio. When I run this as a stored procedure I return nothing. There are no errors, SQL or otherwise. I checked that I am connected to the correct database and the stored procedure is responsible without changing any error chain which is reported of this stored procedure (that code is not shown in the example above). Has anyone seen this problem before, or have experience with SQL/Labview interfaces to tell me what I am doing wrong?
Thanks in advance.
-
HI HI... I'm a student doing a project related to labview. My task is to create a vi, type a user name and password to continue the whole VI.
As I am a newbie to SQL query language, can anyone help me this?... This isn't like the VI with password lock
There is a connection of the user called button in my main façade... u by clicking on it, a pop-up window will come out asking you a user name and a password. If the user name and the password is correct, then you can proceed. The problem is that I'm stuck with database...
Help me pls!with respect,
Ray
Hello
You have two cases:
(1) connect to the database with string (link a string of connection information), and then type something like this:
Driver is SQL Native Client;. Server = IP. Add.re.SS; UID = username; PW = *** ; Database = MyDatabase (depends on your database)(2) use a UDL file (you can configure it to connect to your database, with specific format). Remember that the connection is successful with test button.
There is a UDL file that you can edit here: C:\Program NIUninstaller Instruments\LabVIEW 2010\examples\database\Labview.udl
Edit: The connection dropped, you can set the path to an mdb file, and I think you can give the path of your accdb file.
Kind regards
-
I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.
I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.
Thanks in advance for your help,
Jim
Jim,
Just to be sure, have you used 'is' instead of '=' in this command?
This makes all the difference in this command.
Cerati
-
Support of SQL query: what tasks are Sunday from 07:00 - 12:00
Hello tide Admins.
I need to do a SQL query that can give me a list of jobs that are running on a given (Sunday) day from 07:00 - 12:00. Our environment is not a maintenance window. Therefore, whenever there is application of patches or upgrades, it causes more work and risk of failure of the tide tasks. By moving jobs over the period from 07:00 - 12:00 Sunday, patch can be completed without disrupting the calendar.
Im not the best at the SQL script and can not get my script to work. any help would be great. Here's what I have so far. I get the error ' could not find identifier multi-player jobmst.jobmst_name. IM using Tidal 6.0.3 with SQL for DB Admeral table.
SELECT dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name
FROM dbo.jobdtl INNER JOIN
dbo.jobmst ON dbo.jobdtl.jobdtl_id = dbo.jobmst.jobdtl_id
WHERE (dbo.jobdtl.jobdtl_fromdt > 14 September 2016 06:00 ') AND (dbo.jobdtl.jobdtl_fromdt< '09/11/2016="" 012:00:00="">
GROUP OF dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name
Hi Jeff
The time window from the jobdtl returns only jobs that have an early start time and windows of time from beginning to the end, so there may be some tasks which are not time bound but have dependencies on other jobs, variables, etc.
Here are the 2 SQL queries against the table jobrun and jobmst:
-The list of jobs that took place last Sunday between 07:00 and 12:00
SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_time FROM jobrun
JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
WHERE jobrun.jobrun_time > = 9/11/2016 07:00 ' and jobrun.jobrun_time<= '9/11/2016="" 12:00="">=>
ORDER BY jobrun.jobrun_time-For a list of jobs that are scheduled to run on Sunday to come between 07:00 and 12:00
SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_esttime FROM jobrun
JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
WHERE jobrun.jobrun_esttime > = 9/18/2016 07:00 ' and jobrun.jobrun_esttime<= '9/18/2016="" 12:00="">=>
ORDER BY jobrun.jobrun_esttimeARO
The Derrick
-
How to get the value of a column in sql query?
Hi, anyone knows how to get the value of a column in sql query?
Here is my code, the value must be 1350079224397 in my PB, but I get 0
QString query ("SELECT version FROM db_version");
QVariant result = sda.execute (query);
QVariantMap versionMap = result.toList () such () .toMap ();
If (! versionMap.IsEmpty ())
{
qDebug()<"Version: "="">"Version:><>
}OK, I have the solution
QString query ("SELECT version as version FROM db_version");
-
Hi team,
I'm looking for a SQL query check data (ECC + CallVariable) due to a RESULT of SCRIPT EXECUTE when you ask an external VRU with a translation route to VRU with a 'run external Script '.
In my view, that the data are analyzed between the termination call detail + termination call Variable.
If you have already such a SQL query I would be very grateful to have.
Thanks and greetings
Nick
Omar,
respectfully, shorten the interval of a day might not be an option for a history report ;-)
I recommend to take a look at the following SQL query:
DECLARE @dateFrom DATETIME, @dateTo DATETIME
SET @dateFrom = ' 2014-01-24 00:00:00 '
SET @dateTo = ' 2014-01-25 00:00:00 '
SELECT
TCV. DateTime,
TCD. RecoveryKey,
TCD. RouterCallKeyDay,
TCD. RouterCallKey,
VME. EnterpriseName AS [ECVEnterpriseName],
TCV. ArrayIndex,
TCV. ECCValue
OF Termination_Call_Variable tcv
JOIN THE
(SELECT RouterCallKeyDay, RouterCallKey, RecoveryKey IN Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime)< @dateto)="">
THE tcv. TCDRecoveryKey = tcd. RecoveryKey
LEFT OUTER JOIN Expanded_Call_Variable VME ON tcv. ExpandedCallVariableID = VME. ExpandedCallVariableID
WHERE the tcv. DateTime > @dateFrom AND tcv. DateTime<>
With variables, you can set up your code (for example, you could write SET @dateFrom =? and let the calling application to fill in the DateTime for you).
In addition, join two large tables with all the lines, as you did (TCD - TCV) is never a good option.
Another aspect to consider: all the ECC is actually arrays (always), is not good to leave aside the index value (tcv. ArrayIndex).
G.
-
DA on updatable report items Sql query using the class
Request Express 4.2.5.00.08
10-11 g Oracle
I have a page, so it has a link/button when he clicks then modal region will appear. Modal region has a as a table (Type SQL Query (updateable report)). All work very well so far.
However, I've now added some complex things.
for example. My region is based on the query of SQL Type (editable report).
SELECT id, name of family, Traghetti, area, d_date, start_time, End_time, displacement, role of table where id =: P10_ID;
I can also add a new line of course.
My problem is, (point) Shift display based on the value of Start_Time point) and so I made sure the class for two items.
for example, Start_Time (' class = "st_tm" ') and Maj ('class to = "Shift_time" '). Start_Time is based on (LOV) and shift is off the point in the sql query, but change the Start_Time.
And now, I created the DA.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
1. action: set value
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
The element affected: P10_X1 (it is a hidden item)
2. action: Plsql Code
Code: start to null; end;
Page items to submit: P10_X1
3. action: Plsql Code
Code: start
If: P10_X1 between '03' AND '11' then
: P10_X1: = 'EARLIES ';
elsif: P10_X1 then '12' and '18'
: P10_X1: = 'LATES ';
on the other
: P10_X1: = 'NIGHTS';
end if;
end;
Page items to submit: P10_X1
NOW another DA
Event: change
Article (s) P10_X1
Condition (in list)
value (HASTY, LATES, NIGHTS)
Action:
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
Affected item:
Selection type: jQuery Selector
jQuery Selector:. Shift_time
Well, I look forward all the above work well, but I'm having a problem.
If I have more than 1 lines on a modal region and if I change the Start_Time value for a row then MAJ (point) is changing but he effect on all lines.
I want, if I make the changes on the line line # 2 while only 2 # MAJ (point) must be not performed any other lines?
Help, please!
Kind regards
RI
I found the solution me thank you.
I removed all the DA mentioned above and created a new.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
Scope of the event: dynamic and light on page load.
Action (Javascript code)
ROW_ID = $(this.triggeringElement).attr('id').substr (4);
If ($(this.triggeringElement). val() > = 03 &. val() $(this.triggeringElement))<= 11)="">=>
.Val ('EARLIES') $(«#f11_» + row_id);
}
ElseIf ($(this.triggeringElement). > 11 val() & $(this.triggeringElement). val())<= 18)="">=>
.Val ('LATES') $(«#f11_» + row_id);
}
ElseIf (. val() > $19 (this.triggeringElement)) {}
.Val ('NIGHTS') $(«#f11_» + row_id);
}
also created another DA because I have a disabled report items.
Event: before the page is sent.
$('_:_disabled').removeAttr ("disabled");
and finally created manual process of DML for tabular and everything works fine. (Insert, Update, and delete).
Kind regards.
Maybe you are looking for
-
After sleep extended / "sleep" mode Tecra M11 don't wake up
Hello On a machine of 8 months, if I si je laissais let machine go into Hibernate / sleep mode with power settings, she wakes up not. I can get going again once in removing and replacing the battery. I did a restore of this problem did not exist a fe
-
Installation of Windows 7 very smooth with the new installer
Last night, I installed Windows 7 on my NB205. I used the "Toshiba for Windows 7 Installer", which is available for download from their support site. This utility download the drivers needed and patches and automatically installs. The installation wa
-
Omni 21 HP all-in-one: I need to cut a movie I made for 5 seconds!
Please someone help me... I admit not very smart when it comes to pc... I made a movie with my camera and downloaded into my computer... I need to cut the last 5 seconds turns off the movie... God bless you and please help!
-
S1900-303 monitoring CPU temperature
Hello I am aware that others have asked similar questions... but are - someone out there who knows if I can monitor the temperature of the CPU on my S1900-303...? BIOS (updated Toshiba) give no indication of power management (sensors, etc.) ... I was
-
How activate us the free warranty upgrade?
Hi, just registered my new Satellite Pro. Anyone know how the free warranty upgrade is enabled?See you soon--Ian Post edited by: musicrab