How can I write a query for this?
I have a table as below ,
room.........date.............inventory
A..............01/01.................5
A..............01/02.................5
A..............01/03.................5
A..............01/05.................5
A..............01/06.................5
A..............01/07.................8
I want the output as below
room.....begin_date........end_date......inventory
A............01/01.................01/03..........5
A............01/05.................01/06..........5
A............01/07.................01/07..........8
Is there any suggestion?
Thanks
null
with x as
(select 'A' room, to_date ('01/01/2007', 'mm/dd/yyyy') d, 5 i from dual union all
select 'A' room, to_date ('01/02/2007', 'mm/dd/yyyy') d, 5 i from dual union all
select 'A' room, to_date ('01/03/2007', 'mm/dd/yyyy') d, 7 i from dual union all
select 'A' room, to_date ('01/04/2007', 'mm/dd/yyyy') d, 7 i from dual union all
select 'A' room, to_date ('01/05/2007', 'mm/dd/yyyy') d, 5 i from dual union all
select 'A' room, to_date ('01/06/2007', 'mm/dd/yyyy') d, 5 i from dual
select min (d)
, max (d)
, min (i)
from (
select room
, d
, i
, max (g) over (order by d) mg
from
(select room
, d
, i
, case when lead (i) over (partition by grp order by d) = i
then rownum
end g
from (
select room
, d
, i
, d - rownum grp
from x
order by d
group by mg
Similar Messages
-
How can I write a query for this table?
Dear friends
I have a table with the following structur and data
ID Name Value
1 book 100
2 book 200
3 car 25
4 car 35
5 book 300
now I would like write a query with following out put
Name value
book 100 , 200 , 300
car 25 , 35
(with , Separator) (my oracle version is 10g)
thanksTry this,
SQL> WITH t AS(SELECT 'book' NAME, 100 VALUE FROM dual UNION ALL
2 SELECT 'book', 200 FROM dual UNION ALL
3 SELECT 'car', 25 FROM dual UNION ALL
4 SELECT 'car', 35 FROM dual UNION ALL
5 SELECT 'book', 300 FROM dual)
6 SELECT NAME, LTRIM (MAX (SYS_CONNECT_BY_PATH (VALUE, ',')), ',') VALUE
7 FROM (SELECT NAME, VALUE, ROW_NUMBER () OVER (PARTITION BY NAME ORDER BY VALUE) rn FROM t)
8 START WITH rn = 1
9 CONNECT BY PRIOR rn + 1 = rn
10 AND PRIOR NAME = NAME
11 GROUP BY NAME;
NAME VALUE
book 100,200,300
car 25,35
2 rows selected.
SQL> G. -
How can i write sql query for this result ?
Hello Dear,
Here is the script first.
CREATE TABLE ACC_TEST(
AD_ID NUMBER,
AD_NAME VARCHAR2(50),
AD_SPM_ID NUMBER);
/data are
Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (136,'Saleh Ahmed',129);
Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (142,'Hamidur Rahman',136);
Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (124,'Jasim Uddin',null);
INSERT INTO ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) VALUES (129,'Sazib',124);I Need The Following Result When I Pass A Value Of Ad_Id. For Example I Pass 142 Then Result Should Be
Select Ad_Id,Ad_Name
From..
where ad_id=142
Ad_Id Ad_Name
136 Saleh Ahmed
129 Sazib
124 Jasim Uddin
If I Pass Ad_Id=136 Then Result Should Be
Ad_Id Ad_Name
129 Sazib
124 Jasim Uddin
If I Pass Ad_Id=129 Then Result Should Be
Ad_Id Ad_Name
124 Jasim Uddin Database 10G XE
Any help will be helpfulHi,
HamidHelal wrote:
WoW ! you acutely got my point. How did you understand that ? lLuck guess. Guessing is usually not the best way to solve problems. It's usually faster and more reliable to say exactly what you want, as well as give an example.
ittle bit more i want to know, if i want to restrict the output not more then 2, what would be sql ?Now you're not even giviing an example!
Maybe you want something like this:
SELECT ad_id
, ad_name
FROM acc_test
WHERE LEVEL BETWEEN 2 AND 3 -- Changed
START WITH ad_id = :target_ad_id
CONNECT BY ad_id = PRIOR ad_spm_id
;which will show jsut the parent and the grandparent of the given row.
I do work with forms developer very much. Sql knowledge is as oracle sql book(cerfitication 9i). But this type of sql isn't available there.
where can i learn this type of sql ? Different sql then ordinary ?Certification is a different topic entirely.
There are books and web sites dealing with more advanced techniques. Sorry, I don't know any well enough to recommend them. Some authors (such as Tom Kyte) are consistently good.
Here are a couple of sites that explain CONNECT BY queries:
http://www.adp-gmbh.ch/ora/sql/connect_by.html
http://www.oradev.com/connect_by.jsp -
How should i write a query for this?
Hi i give the follwing query to implement the result,
IT will gives you the result of one country machines information like Total machines failed machines and success machines of their count
Countyr Name CountryCode Total Machines Failed Machines and Succes machines and their perentage
IT ITALY
1000 20
980 98%
like these i want to display the 16 countyr machines information all country information in one palce like table format
i will give you the query to the below here it is the combination of powershell code also used here with sql code.
Code as Country
Name as Country
And below i mentioned OU in bold every where i will put the country code according to the country
like OU=FR
Select
'FR' as 'Code',
'FRANCE' as 'Name',
(select COUNT(*) from ADComputersInfo where
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
(select COUNT(*) from ADComputersInfo where
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
(select COUNT(*) from ADComputersInfo where
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
(select COUNT(*) from ADComputersInfo where
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
(select count(distinct(cn)) from ADComputersInfo where
(ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
and cn in (select name0 from v_R_System)
(select count(distinct(cn)) from ADComputersInfo where
(ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
and cn not in (select name0 from v_R_System)
select count(distinct(cn)) from ADComputersInfo where
(ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
and cn in (select name0 from v_R_System where Client0 =1 and Obsolete0 =0)
select count(distinct(cn)) from ADComputersInfo where
(ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Workstations_Indus,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com'
or
ObjectPath like 'LDAP://eur.gad.schneider-electric.com/CN=%,OU=Servers,OU=FR,OU=Countries,DC=eur,DC=gad,DC=schneider-electric,DC=com')
and cn not in (select name0 from v_R_System where Client0 =1 and Obsolete0 =0)
So here i pass the County code and country name and OU=FR(assigned country code )
so hw we can all these 3 values in all the query can give me the r8 query for this . And i will get the all 16 country information
Ineed exact query hw we can implement..........................................
I might be excepting lot from our side guys...
Thanks !
AdvancedHi
Can you simple post sample data + desired result? Always state what version you are using..
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How can i write the query for the below output
Hi,
I need this kind of output for my report.Please suggest me asap.It's urgent.
Item Description category subinvcode A B C D....................(All Subinventories)
1 AAAA FFF 5 8 (Quantity Values for the corresponding subinventories)
Plz help.I still don't have a clue what you're going on about, but here's an example of pivoting that I've knocked up based on your scatty bit of data which may give some hint to you as to what to do....
SQL> create table inventory as
2 select 1 as item_id, '0016K8731' as item_desc from dual union
3 select 2, '0014R0181' from dual;
Table created.
SQL>
SQL> create table sub_inventory as
2 select 1 as item_id, 'FG_IBM' as sub_item_id, 5 as quantity from dual union
3 select 1, 'FG_HUN', 4 from dual union
4 select 1, 'FG_PSA', 12 from dual union
5 select 2, 'FG_IBM', 1 from dual union
6 select 2, 'FG_HUN', 17 from dual union
7 select 2, 'FG_PSA', 3 from dual;
Table created.
SQL>
SQL> select item_desc, max(fg_ibm) as fg_ibm, max(fg_hun) as fg_hun, max(fg_psa) as fg_psa
2 from (
3 select i.item_desc,
4 decode(s.sub_item_id, 'FG_IBM', quantity, null) as fg_ibm,
5 decode(s.sub_item_id, 'FG_HUN', quantity, null) as fg_hun,
6 decode(s.sub_item_id, 'FG_PSA', quantity, null) as fg_psa
7 from inventory i, sub_inventory s
8 where s.item_id = i.item_id
9 )
10 group by item_desc
11 /
ITEM_DESC FG_IBM FG_HUN FG_PSA
0014R0181 1 17 3
0016K8731 5 4 12
SQL> -
How can I write the loop for this?
public void currentConnectedPlayers (String[ ] connectedPLayers)
//connectedPlayers contains the names of players connected to the server.
//Display the list of connected players, but SELF is not included in the display list
how will I be able to identify "self" within the loop, in order to exclude myself from beig listed....but in coding... i should use "this" instead of
"self"
shoudlnt I?!Never "this" is not a string it is a class, only if it extends String Class,
Since the users are stored in a String array, we need to know what is the information you put in that array is it name, id .
>
otherwise got error -
How can I write HTML code in this forums
Sorry but I didn't know where to post this thread.....
How can I write HTML code in this forums?Hello,
Every piece of code in your post should be wrapped with the forum tags [ code] and [ /code], without the blanks.
In case of the <a> tag, that is not enough. In this case, you have several options. The most elegant one is to use the entity name for the less-then sign - & lt; - without any spaces. Other options is to add a space between the less-then and the ‘a’ character (and make a note of it) or change the less-then character with a left bracket one.
When posting code, you should always use the forum preview option, just to make sure the forum software “understood” your code correctly.
Hope this helps,
Arie. -
CAn we write a query like this
CAn we write a query like this?
If not how can this be changed?
select col1,col2,col3.col4
from table 1
where col1,col2 in(select col1,col2 from table2)Or it may be identical:
SQL> CREATE TABLE t1 (c INT NOT NULL);
Table created.
SQL> CREATE TABLE t2 (c INT NOT NULL);
Table created.
SQL> INSERT ALL
2 INTO t1 VALUES (rn)
3 INTO t2 VALUES (rn)
4 SELECT rownum AS rn FROM user_tables WHERE rownum <= 15;
30 rows created.
SQL> BEGIN
2 DBMS_STATS.GATHER_TABLE_STATS(user,'T1');
3 DBMS_STATS.GATHER_TABLE_STATS(user,'T2');
4 END;
5 /
PL/SQL procedure successfully completed.
SQL> SELECT * FROM t1
2 WHERE EXISTS
3 ( SELECT 1 FROM t2 WHERE c = t1.c )
4
SQL> @xplan
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 15 | 90 | 5 |
|* 1 | HASH JOIN SEMI | | 15 | 90 | 5 |
| 2 | TABLE ACCESS FULL | T1 | 15 | 45 | 2 |
| 3 | TABLE ACCESS FULL | T2 | 15 | 45 | 2 |
Predicate Information (identified by operation id):
1 - access("T2"."C"="T1"."C")
SQL> SELECT * FROM t1
2 WHERE c IN
3 ( SELECT c FROM t2 )
4
SQL> @xplan
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 15 | 90 | 5 |
|* 1 | HASH JOIN SEMI | | 15 | 90 | 5 |
| 2 | TABLE ACCESS FULL | T1 | 15 | 45 | 2 |
| 3 | TABLE ACCESS FULL | T2 | 15 | 45 | 2 |
Predicate Information (identified by operation id):
1 - access("T1"."C"="T2"."C") -
How can we write the code for opening the command prompt and closing the
how can we write the code in java for opening the command prompt and closing the cmd prompt from eclipse (cmd prompt should close when click on the turminate button in eclipse)
rakeshsikha wrote:
how can we write the code for opening the command prompt and closing theBy typing in Eclipse (which you seemingly have)? -
How can i write the trigger for Global Temporary Table
Hi Grus,
How can i write the trigger for Global Temporary Table.
I was created the GTT with trigger using the below script .
CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
EMP_C_NAME VARCHAR2(20 BYTE)
ON COMMIT PRESERVE ROWS;
CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
BEFORE DELETE OR UPDATE OR INSERT
ON GLOBAL_TEMP
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
END;
trigger was create successfully, but the wouldn't insert into to EMPNAME Table..
Please guide whether am correct or not? if not kindly give a correct syntax with example
Thanks in Advance,
Arun M MBEGIN
INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
END;
you are referencing old value in insert stmt.
BEGIN
INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
END;then run ur application it works fine...
CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
EMP_C_NAME VARCHAR2(20 BYTE)
ON COMMIT PRESERVE ROWS;
CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
BEFORE DELETE OR UPDATE OR INSERT
ON GLOBAL_TEMP
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
dbms_output.put_line(:OLD.EMP_C_NAME);
END;
create table EMPNAME as select * from GLOBAL_TEMP where 1=2
insert into GLOBAL_TEMP values('fgfdgd');
commit;
select * from GLOBAL_TEMP;
select * from EMPNAME;
output:
1 rows inserted
commit succeeded.
EMP_C_NAME
fgfdgd
1 rows selected
EMP_C_NAME
fgfdgd
1 rows selectedgot it Arun
Edited by: OraclePLSQL on Dec 28, 2010 6:07 PM -
How Can I change the Authentication for this Dynpage
Hello ,
I have created a rss feed in special Dnypage. When I try to connect with rss reader to dynpage it occurs an error 500. The problem is that no logon screen appears and the portal would start the Dynpage with the User Guest.
How Can I change the Authentication for this Dynpage ? I need a LogonScreen
RSS URL:
/irj/servlet/prt/portal/prtmode/rss/prtroot/com.geberit.ep.uwlquick.uwlquickstarter?mode=rssHi ,
sry the entry in xml does not help. No Logon Prompt
<?xml version="1.0" encoding="UTF-8"?>
<application>
<application-config>
<property name="SecurityArea" value="NetWeaver.Portal"/>
<property name="Vendor" value="xx.com"/>
<property name="PrivateSharingReference" value="com.sap.portal.htmlb,com.sap.portal.pcd.glservice,com.sap.portal.ivs.iviewservice,usermanagement,,com.sap.netweaver.bc.uwl"/>
</application-config>
<components>
<component name="uwlquickstarter">
<component-config>
<property name="SafetyLevel" value="no_safety"/>
<property name="ClassName" value="com.xx.portal.uwl.uwlquickstarter"/>
</component-config>
<component-profile>
<property name="AuthScheme" value="default"/>
</component-profile>
</component>
</components>
<services/>
</application> -
How can i get a solution for this message "Your Apple ID has been disabled"?
How can i get a solution for this message "Your Apple ID has been disabled"?
Contact iTunes Store support. That message can mean one of several things:
Your credit card on file has expired
The credit card issuer has denied a charge
Your account has been hacked
Key information in your account has changed, and Apple needs to contact you to confirm the change. -
How to write a query for this data??
In this table i have column dob which is DATE type,for example 12-jan-89 I want output like this
Year Day
12-jan-89 Thusrs_day
12-jan-90 Friday
upto
12-jan-14 sundaykrishnagopi wrote:
No not like that ,I want up to 2014 year
Ok, so lets say you have table like this
SQL> create table my_table(dob date);
Table created.
SQL> insert into my_table (dob) values( to_date('12-jan-1989', 'dd-mon-yyyy'));
1 row created.
SQL> commit;
Commit complete.
SQL> select * from my_table;
DOB
12-JAN-89
You can write a query like this
select dob + (level -1) dob
, to_char(dob + (level -1), 'fmDay') day_
from my_table
connect
by level <= (dob + interval '25' year) - dob + 1; -
How can I write a script for set left indent?
In three cases as below:
for example:
left indent:8mm; first indent:0mm
left indent:0mm; first indent:8mm
left indent:8mm; first indent:-8mm
How can I write a script to tell Indesign, wherever the text indent is, each time when I run the script once, the text can put just a step rightward, and “one step = 8mm”.
Please!Hi, Trevor
I use change by list as below:
grep {leftIndent:48mm} {leftIndent:56mm}
grep {leftIndent:40mm} {leftIndent:48mm}
grep {leftIndent:32mm} {leftIndent:40mm}
grep {leftIndent:24mm} {leftIndent:32mm}
grep {leftIndent:16mm} {leftIndent:24mm}
grep {leftIndent:8mm} {leftIndent:16mm}
grep {firstLineIndent:8mm, leftIndent:48mm} {firstLineIndent:8mm, leftIndent:56mm}
grep {firstLineIndent:8mm, leftIndent:32mm} {firstLineIndent:8mm, leftIndent:48mm}
grep {firstLineIndent:8mm, leftIndent:24mm} {firstLineIndent:8mm, leftIndent:32mm}
grep {firstLineIndent:8mm, leftIndent:16mm} {firstLineIndent:8mm, leftIndent:24mm}
grep {firstLineIndent:8mm, leftIndent:8mm} {firstLineIndent:8mm, leftIndent:16mm}
grep {firstLineIndent:-8mm, leftIndent:48mm} {firstLineIndent:-8mm, leftIndent:56mm}
grep {firstLineIndent:-8mm, leftIndent:32mm} {firstLineIndent:-8mm, leftIndent:48mm}
grep {firstLineIndent:-8mm, leftIndent:24mm} {firstLineIndent:-8mm, leftIndent:32mm}
grep {firstLineIndent:-8mm, leftIndent:16mm} {firstLineIndent:-8mm, leftIndent:24mm}
grep {firstLineIndent:-8mm, leftIndent:8mm} {firstLineIndent:-8mm, leftIndent:16mm}
but not that perfect,
I want to useing jave "if{}" or "for{}" to write this script, but I don't kown the syntext. -
How can i write properties file for Hindi font
Hi All,
i'm using jdev 11.1.1.5.0
in my use case i have worked on internationalization where i want to use hindi font
like this link -
Majid Hussain: Internationalization of ADF 11.1.1.3 Applications
as in above post majid used german language and write properties file for german language(which is using english character).
but my problem is that i want to use hindi language
so how can i write propery file which support hindi font.
ManishHi Manish,
We also had same requirement where we need to show indian local language(Hindi ,Bengali and many more ).
We had implemented following approach and perhaps it will helpful for you.
1-First we changed the encoding value in jdeveloper.
go to jdeveloper --> tools --->preference-->encoding , select to UTF8
2-We used to get the properties and it's translated value from business and then we were manually put these pair into related resource bundle.
And using this we were able to implemented multilanguage support.
Thanks
Prateek
Maybe you are looking for
-
I can recieve email into Mail app but cannot send email and I get the following error. This message could not be delivered and will remain in your Outbox until it can be delivered. The connection to the server "smtp.mac.com" on port 25 timed out. Wha
-
Mac Pro won't network after 10.5.8 combo update
I just ran the 10.5.8 combo updater and since then my Mac Pro won't connect to my home network. It accesses the internet just fine, but I cannot connect wirelessly to my Macbook or my wifi printer anymore. My Macbook which is still on 10.4.11 can con
-
Why does my photoshop keep giving black and white lines when I use my lasso tool?
why does my photoshop keep giving black and white lines when I use my lasso tool? It has never done this before last night. It filles the Whole lasso seleted box with (what it almost looks like) black and white caution lines. then when I go to zoom o
-
Nokia lumia 521 not support 3g even 2100 band
hy, Dear sir my mobile is nokia lumia 521 and only show 2g even here 3g coverage tell me strong answer i am wait please sir > my mobile only show data connection on and off not show 3g option in cellular so please tell me is this mobile fake compny o
-
How do I delete a corrupted iPhone app from the cloud?
I need to reinstall an iPhone app. The current app has errors in it. I deleted the app, but when I went to reinstall the app, a cloud appeared where the price is usually listed. I was wondering if the same corrupted app is saved on the cloud? If so,