I want SQL query
don't use break i want singal query.
**This EMP table.**
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7,369 SMITH CLERK 7,902 12/17/0080 800.00 NULL 20
7,499 ALLEN SALESMAN 7,698 2/20/0081 1,600.00 300.00 30
7,521 WARD SALESMAN 7,698 2/22/0081 1,250.00 500.00 30
7,566 JONES MANAGER 7,839 4/2/0081 2,975.00 NULL 20
7,654 MARTIN SALESMAN 7,698 9/28/0081 1,250.00 1,400.00 30
7,698 BLAKE MANAGER 7,839 5/1/0081 2,850.00 NULL 30
7,782 CLARK MANAGER 7,839 6/9/0081 2,450.00 NULL 10
7,788 SCOTT ANALYST 7,566 4/19/0087 3,000.00 NULL 20
7,839 KING PRESIDENT NULL 11/17/0081 5,000.00 NULL 10
7,844 TURNER SALESMAN 7,698 9/8/0081 1,500.00 NULL 30
7,876 ADAMS CLERK 7,788 5/23/0087 1,100.00 NULL 20
7,900 JAMES CLERK 7,698 12/3/0081 950.00 NULL 30
7,902 FORD ANALYST 7,566 12/3/0081 3,000.00 NULL 20
7,934 MILLER CLERK 7,782 1/23/0082 1,300.00 NULL 10
**I want result**
DEPARTMENT EMPNO ENAME no of emplyee
10 7839 KING 3
7782 CLARK
7934 MILLER
20 7369 SMITH 5
7902 FORD
7876 ADAMS
7788 SCOTT
7566 JONES
30 7499 ALLEN 6
7521 WARD
7654 MARTIN
7900 JAMES
7844 TURNER
7698 BLAKE
Edited by: apalani06032009 on Jul 2, 2009 5:29 AM
Hi,
SQL> break on count
SQL> select deptno,empno,ename,count(*) over(partition by deptno) count from emp;
DEPTNO EMPNO ENAME COUNT
10 7782 CLARK 3
10 7839 KING
10 7934 MILLER
20 7566 JONES 5
20 7902 FORD
20 7876 ADAMS
20 7369 SMITH
20 7788 SCOTT
30 7521 WARD 6
30 7844 TURNER
30 7499 ALLEN
30 7900 JAMES
30 7698 BLAKE
30 7654 MARTIN
14 rows selected.Regards
Similar Messages
-
I want SQL query to check if any of our important concurrent programs
I want a sql query to check if any of our important concurrent programs are currently scheduled or not
SinghP wrote:
I want a sql query to check if any of our important concurrent programs are currently scheduled or notThat's nice,
What scheduling tool are you using? are you referring to dbms_job?
what version of Oracle are you using? are you using some custom job management system that involves writing to user created tables in your database? -
I want sql query for this output
hi guys
could u tell how can i write sql query for this out put
i have one table like this
ID ACCOUTID TAX
1 1 A
2 1 B
3 2 C
4 2 D
5 3 E
7 NULL F
8 NULL G
MY OUT PUT MUST BE LIKE THIS
ID AID TAX
2 1 A
4 2 D
7 NULL F
8 NULL G
HERE IN THIS OUTPUT I SHOULD HAVE
MAXIMAM ID VALUE FOR A REPEATED AID VALUES
AND
THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
I KNOW ONE SOLUTION LIKE THIS
SELECT MAX(ID),AID,TAX
FROM TABLE T
GROUP BY AID,TAX
UNION ALL
SELECT ID, AIC,TAX
FROM TABLE T
WHERE AID IS NULL;
BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
COULD U PLZ TELL A SOL.Will this help:
SQL> with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21 and (rn = 1 or ACCOUTID is null)
22 /
ID AID T
2 1 B
4 2 D
8 G
7 F
-- If I leave out the OR condition then you'll get this:
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21* and rn = 1
SQL> /
ID AID T
2 1 B
4 2 D
8 G
--which follows the description you've given, but not the output -
Dear Sir/Mam
I want SQL query, function or SP which converts binary data to image (.jpg format).
I m able to convert image (.jpg format) to varbinary. But not able to convert vice versa.
thanks in advance.Binary data is binary data - "image" is only an intrepretation of binary data. Therefore your question makes little sense in the context of sql server since it does not have any facilities to utilize images. Since you provide no context, I'm
guessing that you are trying to retrieve an image stored in the database in a varbinary column and have your application use it as an image. If so, you should post your question to a forum that is specific to your development environment. -
Sql query - help reqd (new)
Hi,
I have follwing dataset
"herb with garden"
"garden without herb"
"herb with zbc"
"garden with pqr"
Now i want sql query like
select * from table where text1 = "herb and garden"
This should populate
herb with garden
garden without herb
And
select * from table where text1 = "herb or garden"
This should populate
"herb with garden"
"garden without herb"
"herb with zbc"
"garden with pqr"SQL> with t
2 as
3 (
4 select 'herb with garden' str from dual union all
5 select 'garden without herb' str from dual union all
6 select 'herb with zbc' str from dual union all
7 select 'garden with pqr' str from dual
8 )
9 select *
10 from t
11 where lower(str) like '%herb%'
12 and lower(str) like '%garden%'
13 /
STR
herb with garden
garden without herb
SQL> with t
2 as
3 (
4 select 'herb with garden' str from dual union all
5 select 'garden without herb' str from dual union all
6 select 'herb with zbc' str from dual union all
7 select 'garden with pqr' str from dual
8 )
9 select *
10 from t
11 where lower(str) like '%herb%'
12 or lower(str) like '%garden%'
13 /
STR
herb with garden
garden without herb
herb with zbc
garden with pqr -
Hi Gurus,
Select * from xxa_test1
invoice_type || LOC_CODE|| seq_no
=========================
DOMESTIC A 1
DOMESTIC B 2
DOMESTIC C 3
Select * from xxa_test2
cust_no || cust_name || loc_code
=======================
1001 Test B
1001 Test C
The Requirement is i want sql query to retrive only one record based on seq no if suppose 2 records retrive in that
B is having seqno 2 and c having seq no 3
that sql query should return only one record which is having min seq no. for example in that B, C only B record should return.
If multiple values returned then the program must check based on the seq no it should take min seq no.
i have written this query
Select *
from xxa_test2 t2
where t2.loc_code in (select t1.loc_code
from xxa_test1 t1
order by Seq_no
where above query is correct or not , i am getting problem with this query.
Please let me know its very urgent
Thanks
Manju
Edited by: venu on Jul 26, 2011 12:50 AMSomething like:
SELECT cust_no, cust_name, loc_code
FROM
(with xxa_test1
as (SELECT 'DOMESTIC' invoice_type, 'A' loc_code, 1 seq_no FROM dual
union all
SELECT 'DOMESTIC', 'B', 2 FROM dual
union all
SELECT 'DOMESTIC', 'C', 3 FROM dual),
xxa_test2
as (SELECT 1001 cust_no, 'Test' cust_name, 'B' loc_code FROM dual
union all
SELECT 1001 , 'Test' , 'C' FROM dual)
SELECT cust_no, cust_name, t2.loc_code, seq_no, min(seq_no) over() min_seq
FROM xxa_test2 t2,xxa_test1 t1
WHERE t2.loc_code = t1.loc_code)
WHERE seq_no = min_seq
SQL> /
CUST_NO CUST L
1001 Test B -
Please i need help,
I want an sql state that will retrieve records from database. I have list of date of birth in a database.
i want the query to list those who are celebrating their birthday a day that the query is run.
Example:
name Date of Birth
Joseph 12/04/1986
Ama 13/04/1978
i want sql query that will return joseph records when is 12/11
Thanks in AdvanceThank you sir, but have a little problem, am running this query in vb6 and my table name is
custab and column is dob, how am i going to use them in vb6 to extract the records. Thanks
BTW this is SQL Server forum. However you can refer below steps,
1. Create a ADO Connection using connection string. You can google how connection string can be used to connect a database.
2. Open the connection.
3. Create a ADO Recordset using the query provided in the above post.
4. Loop the recordset to retrieve the information as,
Do while not rs.eof
msgbox (rs.fields("dob")
rs.movenext
Loop
For more detail refer this link
http://support.microsoft.com/kb/168336
Regards, RSingh -
hi i am face with problem that is i want to show the how much approximate space required for backup or .bak file to get backup using sql query because i want to show the required memory for backup file on my java application
Hi FIROZ
TENNALI
Is this still an issue, or can we close the thread?
* closing a thread by marking the answer/s (there is a link beneath each response) and you can vote for useful responses as well (there is a link to vote on the left of each response)
Ronen Ariely
[Personal Site] [Blog] [Facebook] -
Hi,
I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work
(fault number -2147217900)
I want to search for a value in a ms access table , if it exist i want to update it, if not i want to insert a new row.
Working with LabView 7.1, database con. toolset.
Who can HELP?
Thanks a lot
MarcoHello,
I think that If exist is not a standar SQL command (I know it exists I think in Oracle and SQL server), MS access doesn't support it, so I think the best way to do it is first make a Select and then either an Update or an insert, sorry...
Paulo -
I want to query sql server database from oracle
i want to query sql server database from oracle
can anyone help me in this regardFirst of all - you are in the wrong forum.
Look either for the Database general or search for Transparant / Heterogenous Gateways.
cu
Andreas -
I want to query oracle database from sql server can anyone tell steps 2 fo
i want to query oracle database from sql server can anyone tell steps 2 followed
i tried with linked servers but it is throwing errors can anyone hepl in this regard
The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].First of all - you are in the wrong forum.
Look either for the Database general or search for Transparant / Heterogenous Gateways.
cu
Andreas -
I want to query oracle database from sql server can anyone tell steps 2 fol
i want to query oracle database from sql server can anyone tell steps 2 followed
i tried with linked servers but it is throwing errors can anyone hepl in this regard
The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].First of all - you are in the wrong forum.
Look either for the Database general or search for Transparant / Heterogenous Gateways.
cu
Andreas -
I want to know when a sql-query was excuted in DBA_HIST_SQL_PLAN !!
Hi, all.
I want to know when a sql query wqas excuted in past 3 month.
select * from DBA_HIST_SQL_PLAN
where plan_hash_value='1844343569'
is working?
The plan_hash_value is from v$sql_plan of current instance.
There ware 3times database shutdown/startup.
When a oracle instance is initiated, is the plan_hash_value of the same query changing?
Thanks in advance.You can't go back 3 months unless your retention period is set to that length of time.
select retention from DBA_HIST_WR_CONTROL;
If you want to retain data for longer then you need to modify you snapshots settings, but this can impact your DB if it grows too large.
BEGIN
DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS( retention => 100800);
END;
Then you could get the details out by using something like
select a.SNAP_ID, begin_interval_time, end_interval_time, SQL_ID, PLAN_HASH_VALUE,VERSION_COUNT, FETCHES_TOTAL, EXECUTIONS_DELTA , EXECUTIONS_TOTAL
from DBA_HIST_SQLSTAT a, DBA_HIST_SNAPSHOT b
where b.snap_id=a.snap_id
and b.instance_number=a.instance_number
and sql_id='&sql_id'
; -
Hi All
This is mu use case
1. I have a table called Trades which stores Trades from different clients
2. In Trade Table I have a field called 'TRADE_FEE_REF' which store all the fees for a trade as a reference
3. In table 'TRADE_FEE_DETAILS' it stores the fees related to a perticular trade
4. Trades and TRADE_FEE_DETAILS tables have a foriegn key.
5. Now I want to display the following result for user.
I want a single row for Trades which includes Fee details as columns in that selection
ex: This is a Row from Trade table
Date, quantity, Price, Free_ref_no
1/1/2011, 2000, 12.45 , 1
This is the records from TRADE_FEE_DETAILS for the perticular trade above
Fee_Ref, Fee_type,Fee_amount
1 ,BR, 200
1 ,ST,300
1 ,STT,100
now I want to display the result as follow
Date, quantity, Price, BR,ST,STT
1/1/2011, 2000, 12.45,200,300,100
How do I retrieve this result from sql query
Thnks
PadmaYou can use PIVOT function to convert rows to columns
with trade as
select to_DATE('1-JAN-2011','DD-MON-YYYY') col_date, 2000 quantity, 12.45 Price, 1 Free_ref_no from dual
trade_fee_details as
select 1 Fee_Ref, 'BR' Fee_type, 200 Fee_amount from dual union all
select 1, 'ST', 300 from dual union all
select 1, 'STT', 100 from dual
SELECT
td.col_date,
td.quantity,
td.price,
tf.BR,
tf.ST,
tf.STT
FROM
trade td,
SELECT
FROM
SELECT
FROM
trade_fee_details
PIVOT (SUM(Fee_amount) FOR Fee_type IN ( 'BR' AS BR,'ST' AS ST,'STT' AS STT ))
) tf
WHERE
td.Free_ref_no = tf.fee_ref;
COL_DATE QUANTITY PRICE BR ST STT
01-JAN-11 00:00:00 2000 12.45 200 300 100 -
I want a sql query to diffrentiate the column names between two schemas
The structure of the dba_tab_cols table is owner, table_name, column_name, data_type,.....
So I have a ACCT_ALT_ID table under owner SEODS01 and in that therse are column names
IBD_ID
ACCT_ALT_ID_CNTX_CDE
EODS_ACCT_ID
DATA_GRP_CDE
UPDT_DTE
AND I have a ACCT_ALT_ID table under owner SEODS02 and in that therse are column names
IBD_ID
ACCT_ALT_ID_CNTX_CDE
EODS_ACCT_ID
DATA_GRP_CDE
CRTE_PGM
CRTE_TSTP
UPDT_PGM
UPDT_TSTP
so I want select query to display like this
SEODS1_ACCT_ALT_ID SEODS02_ACCT_ALT_ID (COLUMN HEADER)
IBD_ID IBD_ID
ACCT_ALT_ID_CNTX_CDE ACCT_ALT_ID_CNTX_CDE
EODS_ACCT_ID EODS_ACCT_ID
DATA_GRP_CDE DATA_GRP_CDE
UPDT_DTE CRTE_PGM
CRTE_TSTP
UPDT_PGM
UPDT_TSTP
AND ALSO I NEED ONE MORE QUERY THAT I DO NOT WANT DISPLAY HAVING SAME COLUMN_NAME LIKE ACCT_ALT_ID_CNTX_CDE ,EODS_ACCT_ID,IBD_ID
DATA_GRP_CDEHi,
Welcome to the forum!
876793 wrote:
The structure of the dba_tab_cols table is owner, table_name, column_name, data_type,.....
So I have a ACCT_ALT_ID table under owner SEODS01 and in that therse are column names
IBD_ID
ACCT_ALT_ID_CNTX_CDE
EODS_ACCT_ID
DATA_GRP_CDE
UPDT_DTE
AND I have a ACCT_ALT_ID table under owner SEODS02 and in that therse are column names
IBD_ID
ACCT_ALT_ID_CNTX_CDE
EODS_ACCT_ID
DATA_GRP_CDE
CRTE_PGM
CRTE_TSTP
UPDT_PGM
UPDT_TSTP
so I want select query to display like this
SEODS1_ACCT_ALT_ID SEODS02_ACCT_ALT_ID (COLUMN HEADER)
IBD_ID IBD_ID
ACCT_ALT_ID_CNTX_CDE ACCT_ALT_ID_CNTX_CDE
EODS_ACCT_ID EODS_ACCT_ID
DATA_GRP_CDE DATA_GRP_CDE
UPDT_DTE CRTE_PGM
CRTE_TSTP
UPDT_PGM
UPDT_TSTPYou may have noticed that this site normally doesn't display multiple spaces in a row.
Whenever you post formatted text (such as query results) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
That way, your message will look like this:SEODS1_ACCT_ALT_ID SEODS02_ACCT_ALT_ID (COLUMN HEADER)
IBD_ID IBD_ID
ACCT_ALT_ID_CNTX_CDE ACCT_ALT_ID_CNTX_CDE
EODS_ACCT_ID EODS_ACCT_ID
DATA_GRP_CDE DATA_GRP_CDE
UPDT_DTE CRTE_PGM
CRTE_TSTP
UPDT_PGM
UPDT_TSTP
This sounds like a jon for a FULL OUTER JOIN:SELECT s1.column_name AS seods1_acct_alt_id
, s2.column_name AS seods2_acct_alt_id
FROM dba_tab_cols s1
FULL OUTER JOIN dba_tab_cols s2 ON s1.column_name = s2.column_name
WHERE s1.owner = 'SEODS1'
AND s1.table_name = 'ACCT_ALT_ID'
AND s2.owner = 'SEODS2'
AND s2.table_name = 'ACCT_ALT_ID'
AND ALSO I NEED ONE MORE QUERY THAT I DO NOT WANT DISPLAY HAVING SAME COLUMN_NAME LIKE ACCT_ALT_ID_CNTX_CDE ,EODS_ACCT_ID,IBD_ID
DATA_GRP_CDESorry, I don;t understand.
Post the results you want (formatted, between \ tags, of course).
Do you want only the column names that appear in one table or the other, but not in both?
In that case, you can add a condition like this to the WHERE clause:
AND ( s1.column_name IS NULL
OR s2.column_name IS NULL
)
Maybe you are looking for
-
Issue while submitting concurrent program from OAPage
Hi Team, In OApage in One LOV field is der. From that LOV we need to select one concurrent program and click next button. while clicking on the next button i am getting error like below The data that defines the flexfield on this field may be incons
-
Send error messages in DatabaseMail when SQL Job fails/succeeds
Hi , I have setup a profile and account for sending mail using DatabaseMail. I have a SQL JOB. If the job fails, I receive an Email. Till this point, everything works fine. This is what the email looks like : JOB RUN: 'GenerateJVForLabourAndOverheads
-
Multiple Details Sections in the same report
I'm trying to take two different columns from a fact table, and display them in one column on the report. So I'll then have the charge quantities (grouped and summarized) listed above the charge amounts (grouped and summarized) across months (columns
-
My mail smart groups are too large for server - How do I make smart groups smaller e.g. A-F, G-L, M-S T-Z? Any help appreciated
-
"Import Flex Project" Menu Disappear [FB 4.6]
Hi All, I am not sure what's going wrong here but I'm not able to see "Import Flex Project" menu item under File Menu. Can any one knows how to get it back ? Thanks Mac