Help needed in the a sql query
hi,
i have small but tricky piece of requirements,
following is the input
Id id_type id_level id_name
1 F A_1 Beta1
2 W A_1 Beta2
3 W A_1 Beta3
4 L A_1 Alpha0
5 W A_1 Beta4
6 W A_1 Beta5
now whenever
Id_level = A_1, and id_name = Alpha0 and id_type = L then
id_level = B_1
and the coming next 2 levels after this should have id_level C_1
the output should be as follows
Id id_type id_level id_name
1 F A_1 Beta1
2 W A_1 Beta2
3 W A_1 Beta3
4 L B_1 Alpha0
5 W C_1 Beta4
6 W C_1 Beta5
kindly let me know if this could be possible in sql,
if i am missing something here plz highlight it to me,
kindly give me some tips or hints,thanks and regards
nic
SQL> WITH Test_Data AS (
2 SELECT 1 AS Id, 'F' AS Id_Type, 'A_1' AS Id_Level, 'Beta1' AS Id_Name FROM Dual UNION ALL
3 SELECT 2, 'W', 'A_1', 'Beta2' FROM Dual UNION ALL
4 SELECT 3, 'W', 'A_1', 'Beta3' FROM Dual UNION ALL
5 SELECT 6, 'L', 'A_1', 'Alpha0' FROM Dual UNION ALL
6 SELECT 8, 'W', 'A_1', 'Beta4' FROM Dual UNION ALL
7 SELECT 10, 'W', 'A_1', 'Beta4' FROM Dual UNION ALL
8 SELECT 11, 'W', 'A_1', 'Beta5' FROM Dual
9 )
10 SELECT Id, Id_Type,
11 CASE WHEN Id_Level = 'A_1' AND Id_Name = 'Alpha0' AND Id_Type = 'L'
12 THEN 'B_1'
13 WHEN COUNT(CASE WHEN Id_Level = 'A_1' AND Id_Name = 'Alpha0' AND Id_Type = 'L' THEN 1 ELSE NULL END)
14 OVER(ORDER BY Id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) = 0
15 THEN Id_Level
16 WHEN COUNT(CASE WHEN Id_Level = 'A_1' AND Id_Name = 'Alpha0' AND Id_Type = 'L' THEN 1 ELSE NULL END)
17 OVER(ORDER BY Id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) > 0
18 THEN 'C_1'
19 END AS Id_Level,
20 Id_Name
21 FROM Test_Data
22 ORDER BY Id;
ID I ID_ ID_NAM
1 F A_1 Beta1
2 W A_1 Beta2
3 W A_1 Beta3
6 L B_1 Alpha0
8 W C_1 Beta4
10 W C_1 Beta4
11 W C_1 Beta5
7 rows selected.Regards,
Dima
Similar Messages
-
Help needed in building a sql query
Hello,
I am using Oracle 10g db.
I have 3 tables table1 and table2 and table3
I am writing one sql query which is like
select table1.a a1,(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
from table1
Now the b1 value may give more then 1 values so when i am trying to execute the query its giving me error.
What i would like to have is if it gives returns more then 1 value then add that value as a new column means if b1 gives like abc and def as values.
Then i want the sql to return like
acolvalue abc def as a single row.
Is this possible to do?
ThanksHello,
The approach which i took is i wrote a function which gives me the b values , sseparated.
Then i am building a outer query considering the max of b so i just found there are max 10 values which one row is showing.
select b11,b12,b13,,,b10
from (
select table1.a a1,func(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
from table1)
but now i am facing problem like the value of b1 is a,b,c
i want to use the substr and instr function to get
a as b11
b as b12
c as b13
can anyone pls help me out to write a query? i am getting b11 but other values are somehow not coming.
for b11
i used
substr(b1,1,instr(b1,',',1,1)-1)
Thanks -
Help needed on writing a SQL query
Here is my table that shows records of 3 ORDER_ID (10, 20 and 30). All I need to do is, pick the first record of each order_id and check the event_id, if the event_id is same for the next record, ignore it, else show it and ignore rest all records for that order_id. This way my query output will show only two records for each ORDER_ID. Query should produce records that are in BOLD in the sample data. (Database - 11g)
Thanks for your help in advance
ORDER_ID EVENT_ID EVNT_DATE STATE_CODE
*10 16937555 20100212 COMPLETE*
10 16937555 20100212 ACTIVE
*10 16308004 20100129 OCCURRED*
10 16131904 20100125 ACTIVE
10 16270684 20100128 OCCURRED
10 14899116 20091213 ACTIVE
10 16085672 20100123 COMPLETE
10 16085673 20100123 OCCURRED
10 14899119 20100123 COMPLETE
10 14899120 20100123 COMPLETE
*20 17134164 20100223 COMPLETE*
20 17134164 20100223 ACTIVE
20 17134164 20100223 STARTED
*20 15479131 20100105 OCCURRED*
20 15478409 20100105 OCCURRED
20 15478408 20100105 ACTIVE
20 15119404 20100105 COMPLETE
20 14346123 20091129 ACTIVE
20 15467821 20100104 OCCURRED
20 14346125 20091216 COMPLETE
20 14346126 20091215 COMPLETE
20 14346126 20091214 COMPLETE
*30 18814670 20100412 COMPLETE*
30 18814670 20100412 ACTIVE
*30 18029509 20100320 OCCURRED*
30 16853720 20100211 ACTIVE
30 17965764 20100319 OCCURRED
30 16386708 20100211 COMPLETE
30 16804451 20100211 OCCURRED
30 15977897 20100121 ACTIVE
Edited by: sarvan on Aug 12, 2011 7:16 AMtry this [Not fully tested]
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Elapsed: 00:00:00.00
SQL> SELECT *
2 FROM (SELECT order_id, event_id, evnt_date, state_code, next_evntid,
3 ROW_NUMBER () OVER (PARTITION BY event_id ORDER BY NULL)
4 AS rownm
5 FROM (WITH t AS
6 (SELECT 10 AS order_id, 16937555 AS event_id,
7 20100212 AS evnt_date, 'COMPLETE' AS state_code
8 FROM DUAL
9 UNION ALL
10 SELECT 10, 16937555, 20100212, 'ACTIVE'
11 FROM DUAL
12 UNION ALL
13 SELECT 10, 16308004, 20100129, 'OCCURRED'
14 FROM DUAL
15 UNION ALL
16 SELECT 10, 16131904, 20100125, 'ACTIVE'
17 FROM DUAL
18 UNION ALL
19 SELECT 10, 16270684, 20100128, 'OCCURRED'
20 FROM DUAL
21 UNION ALL
22 SELECT 20, 17134164, 20100223, 'COMPLETE'
23 FROM DUAL
24 UNION ALL
25 SELECT 20, 17134164, 20100223, 'ACTIVE'
26 FROM DUAL
27 UNION ALL
28 SELECT 20, 17134164, 20100223, 'STARTED'
29 FROM DUAL
30 UNION ALL
31 SELECT 20, 15479131, 20100105, 'OCCURRED'
32 FROM DUAL) -- End of test data
33 SELECT order_id, event_id, evnt_date, state_code,
34 LEAD (event_id, 1, 0) OVER (PARTITION BY order_id ORDER BY NULL)
35 AS next_evntid
36 FROM t)
37 WHERE event_id = next_evntid)
38 WHERE rownm <= 2
39 /
ORDER_ID EVENT_ID EVNT_DATE STATE_CO NEXT_EVNTID ROWNM
10 16937555 20100212 COMPLETE 16937555 1
20 17134164 20100223 COMPLETE 17134164 1
20 17134164 20100223 ACTIVE 17134164 2
Elapsed: 00:00:00.00
SQL> PS - You should seriously think about ordering the data before you do this kind off operations.
Edited by: Sri on Aug 12, 2011 9:12 AM -
Combine multiple web services with the same SQL query into one
Hello,
I would like to ask a question regarding combine multiple similar web services into one. Can you please tell me if it is possible to combine 4-5 web services into one since they built on the same SQL query with 5 different criterias or condition so that the user can enter any of the 5 criterias to populate the data on the form instead of having 5 different web services?
e.g Query: Select appName, permit#, address, phone, description, type, section, from table where appName = can be 'appName, permit#, address, phone, or description' to populate the rest of the data to the form.
Does any one have ever done some thing like this in Workbench ES? If so please assist. I know it can be easier to build it in Visual Basic, C#, or dot.net but the requirement is to build it in workbench ES.
Thanks in advance,
Han DaoIf you are querying for Name, PhoneNumber, and SSN, and you queried for all people with a phone number that started with 867, you would have a potentially long list of people. So to keep track of all of the people, we store each record in XML complex elements. The root node is just any name you want, and the repeating element is the complex element name.
So using the example from above, I'm going to specify the following:
Root Node: Result
Repeating Element: Person
So now when I do a query, my resultXML will look like:
<Result>
<Person>
<Name>Alex</Name>
<PhoneNumber>867-5309</PhoneNumber>
<SSN>111-11-1111</SSN>
</Person>
</Result>
If your query returned multiple results (like ours would probably), it would look like:
<Result>
<Person>
<Name>Alex</Name>
<PhoneNumber>867-5309</PhoneNumber>
<SSN>111-11-1111</SSN>
</Person>
<Person>
<Name>Han</Name>
<PhoneNumber>867-2169</PhoneNumber>
<SSN>222-22-2222</SSN>
</Person>
</Result>
So Result and Person is just to give a little bit of structure to the xml result (containers really). So you can name them whatever is helpful for you.
The column name mappings map the query columns (Name, PhoneNumber, SSN) to some node in the XML (Name, PhoneNumber, SSN). So you don't need to specify which field maps to what in the form. Just copy the column names to the element name so you have a 1-to-1 naming. If you want to manipulate the XML a bit though, you could do:
Column Name Element
Name YourName
PhoneNumber Phone
SSN Secret
which would then make your xml look like:
<Result>
<Person>
<YourName>Alex</YourName>
<Phone>867-5309</Phone>
<Secret>111-11-1111</Secret>
</Person>
</Result>
It lets you change the XML element names to whatever you want. Otherwise by default they take on their column names.
In your form, you could bind to the WSDL through the Data Connections pane and point it to your web service. This will then create form elements that you can just drag and drop allowing you to have the information available when the service gets ran. Once the service is called, you can modify the field's data to get whatever information you need in order to populate other form fields.
If that is too confusing, feel free to send me your form (e-mail is on profile page) and I'll add comments to it to show you how to set up the form for the web service call (and also give me the link to your webservice) -
Extracting the Logical sql query for the specified report in OBIEE 11g
Hi ,
I want to extract the logical SQL Query for the Particular report in OBIEE 11.1.1.5.
Any pointers related to this will be very helpful.
Thanks,
Sonalifor a try please add Logical sql view to ur report it will dispaly the Logical sql for that Report..
Hope it will helps you. -
Can we implement the custom sql query in CR for joining the two tables
Hi All,
Is there anyway to implement the custom sql query in CR for joining the two tables?
My requirement here is I need to write sql logics for joining the two tables...
Thanks,
GanaIn the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
Log on to your data source if necessary.
Under your data source, double-click the Add Command node.
In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
For example:
SELECT
Customer.`Customer ID`,
Customer.`Customer Name`,
Customer.`Last Year's Sales`,
Customer.`Region`,
Customer.`Country`,
Orders.`Order Amount`,
Orders.`Customer ID`,
Orders.`Order Date`
FROM
Customer Customer INNER JOIN Orders Orders ON
Customer.`Customer ID` = Orders.`Customer ID`
WHERE
(Customer.`Country` = 'USA' OR
Customer.`Country` = 'Canada') AND
Customer.`Last Year's Sales` < 10000.
ORDER BY
Customer.`Country` ASC,
Customer.`Region` ASC
Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
For more information about creating parameters, see To create a parameter for a command object.
Click OK.
You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
Note:
To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
By default, your command is called Command. You can change its alias by selecting it and pressing F2. -
How to obtain the transformed SQL query using SEM_MATCH
Dear all,
Is it possible to get the transformed relational SQL query when using the SEM_MATCH prefix, by querying directly on the database. We are able to obtain the relational SQL query using Joseki/Jena, however this is not the way to go for us. We would like (if possible) to get it straight from the oracle database by logging or something.
Kind regards.
MaxHi Max,
Just to clarify. What SEM_MATCH prefix are you talking about?
A SEM_MATCH based query is indeed a SQL query as SEM_MATCH is a SQL table function. So if you don't want to go through Java APIs or web service endpoint, then running SEM_MATCH directly should give you what you need. Or maybe you just want to see the underlying generated (from SEM_MATCH) SQL query. If that is true, can you please tell us why?
Thanks,
Zhe Wu -
How to find the backend SQL query of the JSP page in OIC
Does anybody how the best way to find the backend SQL QUERY of OIV JSP page?
How To Generate Trace Files in in HTML/JSP (using Profile Option)
Note: This requires proper responsibility to set SQL Initialization statement using Profile option.
Step 1. Login to the desired Form application.
Step 2. Select +Profile >> System ('Find System Profile Values' screen will pop up)
Step 3. Check 'User' and Type in the Username (in which the account for that user will be trace)
Step 4. Type 'Initialization%' in the Profile box and Hit 'Find' (Click here for preview.)
Step 5. In the User box, type the following statement and Hit 'Save' (Click here for preview)
BEGIN FND_CTL.FND_SESS_CTL('','','TRUE','TRUE','','ALTER SESSION SET TRACEFILE_IDENTIFIER = TESTING MAX_DUMP_FILE_SIZE = 5000000 EVENTS ='||''''||' 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12'||'''');END;
Note: specify any name you like to identify your trace, in this case, testing is the end name on the trace. You can also specify the amount of data allowable to be in the trace, in this case, 5000000 is the amount set. Make sure you hit 'Save' afterwards.[Quotes in the statement are all 'Single' quotes.]
specifying TRACEFILE_IDENTIFIER value is mandatory when setting up the trace using the above profile option value
Step 6. Login to HTML / JSP page with username/password and start your flow. (Everything you do once login to HTML / JSP will get trace.)
Step 7. Logout of HTML / JSP application once you completed with your flow.
Step 8. Go back to the Profile option in the Form application and delete the Initialization SQL statement, and Hit 'Save'.
Step 9. Log in to the database server or login server and retrieve your trace file.
Identify and retrieve the trace file using the tracefile_identifier specified in Step 5.
In this case the tracefile_identifier is TESTING. (Click here for Trace file locations) *
Note: If you need to regenerate your trace or tracing a new flow, then repeat Step 1 to Step 8. To avoid self-confusion, choose a different name for your trace identifier everytime you set to trace.
Step 10. See TKPROF section on how to format trace file into readable text.
Trace Options Definition
No Trace Tracing is not activated
Activities will not get traced.
Regular Trace
(Level 1) Contains SQL, execution statistics, and execution plan.
Provides execution path, row counts as well as produces smallest flat file.
Trace with Binds
(Level 4) Regular Trace plus value supplied to SQL statement via local variables.
Trace with Waits
(Level 8) Regular Trace plus database operation timings that the SQL waited to have done in order to complete, i.e. disk access.
Trace with Binds and Waits
(Level 12) Regular trace with both waits and binds information.
Contains the most complete information and will produce the largest trace file.
****Send me an email to [email protected],I will share the document with you. -
i hav select query like this:-
SELECT COUNT(*) INTO NO_OF_WORKERS FROM PA0000
WHERE ENDDA = '99991231' AND STAT2 = '3'.
with this select query , i can get the no. of workers .
How can i get the no. of workers in the recording period <u><b>excluding</b></u> those persons who were absent from work on paid/unpaid leave for the entire period?Hi Hari,
I got the solution for you.use the following sql query.
SELECT COUNT(*) INTO NO_OF_WORKERS
FROM PA0000 AS a inner join PA2001 as b on apernr = bpernr
WHERE aENDDA = '99991231' AND aSTAT2 = '3'
and ( bawart = '0100' or bawart = '0727' ).
Now onething, in my comapany, in PA2001, field awart = '0100' means paid leave and 0727 means unpaid leave.
this things r configured in SPRO. so must replace the values of awart in sql qurey as per the values of paid/unpaid leave in your company.
you can do one thing, go to infotype pa30..then put 2001 in the infotype field in that screen, put cursor in STy field , hit F4 , it will show you the value for paid unpaid leave.
Note the value , modify the value of awart field inthe sql query, thats it.
cheers, and hey dont forget to give reward points. -
Changing the JCA SQL query in runtime
Hi,
Is it possible to change the predefined sql query in JCA during runtime in OSB.
Regards,
AbdulAbdul,
It won't be possible as structure of request and response is tightly coupled with the SQL and any update in SQL may also require corresponding update in XSD.
Regards,
Anuj -
What Option Allows Permanent Change of Query in the Show SQL Query Window?
I am trying to create a report in Crystal Reports v8.5 (or v10). I would like to create the report by simply cutting and pasting an SQL query from SQL Designer into the appropriate place in Crystal Reports. I can paste the query into the "Show SQL Query" window, but it reverts back to something else. What Option do I change to allow me to do that, i.e, change the query in the "Show SQL Query" window?
Hi Alan,
In CR10 there is no option to past SQL qurety in Show Sql command option. There is another option provided 'Add Commad' to execute customized SQL queries. After connecting to your datasource before selecting tables you can choose Add Command option and past your SQL queries.
Also you can modify the queries which you have pasted in add command.
Thanks,
Sastry -
Need to run a sql query in the background and display the output in HTML
Hi Guys,
I have a link in my iprocurement webpage, when i click this link, a query (sql query) should be run and the output should be displayed in a HTML page. Any ideas of how this can be done. Help appreciated.
We dont have OA Framework and we r using 11.5.7.
help needed
thanxRead Metalink Note 275880.1 which has the link to developer guide and personalization guide.
-
Need help in UPDATE data in SQL Query
Hi all,
I am trying to update data in the sql table as per below screenshot but couldn't able to do it. Can anyone help to update the data as I mention in screenshot.Appreciate you help.Thanks.
Yellow highlighted columns are source
Green highlighted columns are target
Colored data should be update as per source data in sql table.Data is not static as it might have more rows to update and query should be bit dynamic.
Maruthi...You have already asked this question once. You did not get any good answers, because you the information you gave was insufficient. And I'm afraid that the information is still in sufficient.
Or more exactly, from the example you have given, the answer is: can't be done. And the reason it can't be done, is as I explained in response to you first thread: there is no information in the data to from which we can deduce that Clorox Company
should be under "Week 1-1,K.B,F". The fact that rows are listed in a certain order in the screenshoot is of no importance, because a table is an unordered object.
But you said in another post that you have a timestamp column. Maybe that column is usable - maybe it is not. But at least it is a key that you have more columns that the ones you show.
The best way to get help with this type of problems is to post:
1) CREATE TABLE statement for your table(s).
2) INSERT statements with sample data.
3) The desired result given the sample.
4) A short description of the actual buisness problem you are trying to solve.
5) Which version of SQL Server you are using.
This makes it easy to copy and paste into a query window to develop a tested solution. Screenshots with an insufficient amount of data is not going to help you very much.
Erland Sommarskog, SQL Server MVP, [email protected] -
The best SQL query tool to visualize data relationship
Bay Breeze Software just released SQL Edge 1.4, please refer to http://www.baybreezesoft.com for product details.
SQL Edge is an Eclipse Rich Client application that allows users to execute SQL queries, browse schema information in ER diagrams, and visualize data relationships. With SQL Edge, users can use only one query to retrieve data in a master table, and then browse data in all related detail tables. Users can also insert, edit, and delete table records in the data grids.
SQL Edge has five perspectives. The "Query Perspective" allows users run any SQL queries, while the "Schema Perspective" displays table schema information.
There are two relationship perspectives. The "Relationship Table View" displays data in the master-detail style. The "Relationship Tree View" displays master table records as top-level tree nodes. The nodes can be expanded to reveal any level of related detail records. In addition, clicking any node will display the corresponding data in a detail grid.
The "Model Perspective" displays tables and their relationships in ER diagrams. The tables can be from different databases. Users can define master-detail relationships among these tables, and print or save the diagram for future reference.
The version 1.4 added following features:
(1) Added support for synonyms and CLOB data type.
(2) Added load on demand feature to support large result sets. In query perspective and relationship table view, a selection query will only fetch enough rows to populate the data grids. Users can scroll down the grids to fetch more rows if needed.
The version 1.3 added following features:
(1) Added model perspective to display tables and their relationships in ER diagrams. The tables can be from different databases. Users can define master-detail relationships among these tables, and print or save the diagram for future reference.
The version 1.2 features are:
(1) Support any JDBC compatible databases.
(2) Allow users to specify JDBC drivers at run-time, and provide wizards to help setup JDBC connections. Easy to install, and easy to setup.
(3) SQL editor with syntax highlighting based on currently connected databases.
(4) SQL edtior allows users to execute SQL queries asynchronously. Users can cancel the execution by click the "Cancel" button or just close the SQL Editor.
(5) Schema perspective displays the table schema information, including column definitions, primary key, indexes, and foreign keys.
(6) Relationship table view displays the related data in the master-detail style, with master table data shown in the top grid, and all related detail table data in a list of bottom grids.
(7) Relationship tree view displays the master table records as top-level tree nodes, and the related detail records as child nodes. Click any of these tree nodes will display the corresponding record data in a detail grid.
(8) Allow users to insert, edit, and delete records in the master and detail grids of the relationship table view and relationship tree view.
(9) Allow users to define master-detail relationships even between tables in different databases. This enables the relationship table view and relationship tree view to display data relationships between tables in different databases or without pre-defined foreign keys.Good to know. Thank you for the information.
Bye, Aron -
Help Required -- Can we use SQL Query to READ data from SAP MDM Tables
Hi All,
Please help.........
Can we use SQL Query to READ(No Creation/Updation/Deletion just Read) Data from SAP MDM tables directly, without using MDM Syndicator.
Or direct SQL access to SAP MDM tables is not possible. Only through MDM Syndicator can we export data.
Thanks in Advance
RegardsAll the tables you create in Repository comes under A2i_CM_Tables in Database named as your repository name. So the tables names are fields of table A2i_CM_Tables. Now i tried it but cant make it.
Now, I dont think its possible to extract all fields in tables and there values using select query. May be pure sql guy can do that or not.
But there is no relation of data extraction and syndicator. Data is viewed in Data Manager. and you can also store data in a file from DM also.
BR,
Alok
Maybe you are looking for
-
I have recently updated my phone and am attempting to sync it. I got the error message "iTunes could not back up the iPhone because the backup was corrupt or not compatible with the iPhone". I deleted the backup, restarted my computer, and even res
-
SQL query log File..
Hi All, I am using a standalone BIP environment... Is there way we can see the actual query log the BIP generates? which location on the server..or how to get it activated. I want to see what is the actual sql query that is generated along with varia
-
No optical output apple tv (2)
My Apple TV (2) --OS 5.0.2-- does not have sound output vía optical Toslink connection... I´ve tried all options in audio/video menu... Of course HDMI works fine in image and sound, but I need optical output to connect to DAC in a just music system..
-
Why is the New Firefox so slow and why is it "Not Repsonding" most of the time?
I upgraded my home PC to Firefox 4 and it is slower than Firefox 3, it is often not responding causing wait times. I never had this problem with Firefox 3, I have not upgrade my work PC to Firefox 4 for this reason. It's supposed to be faster but it'
-
Can't export MP3 audio from Premiere Elements 9
I want to export the audio from my movie. The File, Export option appears to be unavailable, regardless of what I do; I saw elsewhere on the forum that all exporting is now done through the Share tab, and referring to PE8, the post recommended the "