Please write a query for given senario
Hai All,
Name Date
anil 05/28/12
anil 05/25/12
anil 05/24/12
anil 05/23/12
anil 05/22/12
anil 05/21/12
anil 05/18/12
anil 05/17/12
anil 05/16/12
anil 05/15/12
suma 05/28/12
suma 05/25/12
suma 05/24/12
suma 05/23/12
suma 05/15/12
This is the only sample data of the employee attendance table.I want know those who are absent in the last 10 days and also not consider the days Sunday and Saturday.
Example
Anil : He had present in all the days, no need to display 'Anil' name
Suma : She had not present in all the day, then show the 'Suma' name with 'Absent Days' (05/22/12,05/21/12, 05/18/12, 05/17/12, 05/18/12)
This is the only sample data.
Edited by: adam on May 28, 2012 3:44 AM
Edited by: adam on May 28, 2012 3:47 AM
First of all, hijacking someone's topic is not welcome. Said that, meditate over the difference:
SQL> with tab as (
2 select 'anil' name,to_date('05/28/12','mm/dd/rr') dt from dual union all
3 select 'anil',to_date('05/25/12','mm/dd/rr') from dual union all
4 select 'anil',to_date('05/24/12','mm/dd/rr') from dual union all
5 select 'anil',to_date('05/23/12','mm/dd/rr') from dual union all
6 select 'anil',to_date('05/22/12','mm/dd/rr') from dual union all
7 select 'anil',to_date('05/21/12','mm/dd/rr') from dual union all
8 select 'anil',to_date('05/18/12','mm/dd/rr') from dual union all
9 select 'anil',to_date('05/17/12','mm/dd/rr') from dual union all
10 select 'anil',to_date('05/16/12','mm/dd/rr') from dual union all
11 select 'anil',to_date('05/15/12','mm/dd/rr') from dual union all
12 select 'suma',to_date('05/28/12','mm/dd/rr') from dual union all
13 select 'suma',to_date('05/25/12','mm/dd/rr') from dual union all
14 select 'suma',to_date('05/24/12','mm/dd/rr') from dual union all
15 select 'suma',to_date('05/23/12','mm/dd/rr') from dual union all
16 select 'suma',to_date('05/15/12','mm/dd/rr') from dual
17 )
18 select s.name,
19 dat.dt
20 from
21 tab s right outer join (
22 select trunc(sysdate - level + 1) dt
23 from dual connect by level <= 14
24 ) dat
25
26 partition by (s.name)
27 on ((s.dt) = (dat.dt))
28 where s.dt is null
29 and to_char(dat.dt ,'d') not in (1,7)
30 order by s.name,
31 dat.dt
32 /
no rows selectedand
SQL> with tab as (
2 select 'anil' name,to_date('05/28/12','mm/dd/rr') dt from dual union all
3 select 'anil',to_date('05/25/12','mm/dd/rr') from dual union all
4 select 'anil',to_date('05/24/12','mm/dd/rr') from dual union all
5 select 'anil',to_date('05/23/12','mm/dd/rr') from dual union all
6 select 'anil',to_date('05/22/12','mm/dd/rr') from dual union all
7 select 'anil',to_date('05/21/12','mm/dd/rr') from dual union all
8 select 'anil',to_date('05/18/12','mm/dd/rr') from dual union all
9 select 'anil',to_date('05/17/12','mm/dd/rr') from dual union all
10 select 'anil',to_date('05/16/12','mm/dd/rr') from dual union all
11 select 'anil',to_date('05/15/12','mm/dd/rr') from dual union all
12 select 'suma',to_date('05/28/12','mm/dd/rr') from dual union all
13 select 'suma',to_date('05/25/12','mm/dd/rr') from dual union all
14 select 'suma',to_date('05/24/12','mm/dd/rr') from dual union all
15 select 'suma',to_date('05/23/12','mm/dd/rr') from dual union all
16 select 'suma',to_date('05/15/12','mm/dd/rr') from dual
17 )
18 select s.name,
19 dat.dt
20 from
21 tab s
22 partition by (s.name)
23 right outer join (
24 select trunc(sysdate - level + 1) dt
25 from dual connect by level <= 14
26 ) dat
27 on ((s.dt) = (dat.dt))
28 where s.dt is null
29 and to_char(dat.dt ,'d') not in (1,7)
30 order by s.name,
31 dat.dt
32 /
NAME DT
suma 16-MAY-12
suma 17-MAY-12
suma 18-MAY-12
suma 21-MAY-12
suma 22-MAY-12
SQL> But still, query can produce wrong results. Why? It is NLS-dependent. If your query will be executed by a client in, for example, Germany, your query will filter out Mondays and Sundays. In, for example, Saudi Arabia it will filter out Friday and Saturday.
SY.
Similar Messages
-
Write a query for which has its field name as input parameter
Hi All,
I need to write a query for SSRS report. StartDate, EndDate and ChangedField are the input parameters.
Let's consider that we are taking employee details. The table contains lot of fields like emp name,add1,add2,city,state,country,designation,rank etc. We have almost 30 fields are there. These field name are coming as input parameter "ChangedField"
. I need to show the records which belong to the start date and end date also data change for the field which is given in the input parameter "ChangedField". That meand If I give ChangedField="city", we need to check for data which
has been updated with new City name in the given time period.
Please suggest.
Regards,
JulieHi Julie,
Per my understanding that you have many fields in the table to be displayed in the report, some of the fields will always show and others should be hide and show based on the selection of the parameters which include the columns names, right?
By default, we can't display columns dynamically in the report automatically without insert this column in the report before. So, in your scenario, I will suggest you to add all the columns in the reports first and then add show/hide expression on
the column visibility based on the selection of the parameter "ChangedField", when some of the fields selectted they will be display, otherwise they will be hidden. For the fields which you want to be always displayed will not need to add the expression
in the column visibility.
Details steps about how to acheive this, please referencet to the article below:
Displaying Dynamic Columns in SSRS Report
If you still have any problem, please feel free to ask.
Regards,
Vicky Liu
Vicky Liu
TechNet Community Support -
How to write sql query for counting pairs from below table??
Below is my SQL table structure.
user_id | Name | join_side | left_leg | right_leg | Parent_id
100001 Tinku Left 100002 100003 0
100002 Harish Left 100004 100005 100001
100003 Gorav Right 100006 100007 100001
100004 Prince Left 100008 NULL 100002
100005 Ajay Right NULL NULL 100002
100006 Simran Left NULL NULL 100003
100007 Raman Right NULL NULL 100003
100008 Vijay Left NULL NULL 100004
It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains both left_leg and right_leg id, then it is called pair.)
I know there are three pairs under id "100001" :-
1. 100002 and 100003
2. 100004 and 100005
3. 100006 and 100007
100008 will not be counted as pair because it does not have right leg..
But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005Sounds like this to me
DECLARE @ID int
SET @ID = 100001--your passed value
SELECT left_leg,right_leg
FROM table
WHERE (user_id = @ID
OR parent_id = @ID)
AND left_leg IS NOT NULL
AND right_leg IS NOT NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Need to write SQL query for hierarchy
Hi Guys,
I need help to write a query for the below scenario.
I have one organization, under that I have many branches. when i provide input to query on last branch, i need to display all parents of that branch like below
Organization ---parent
branch 1 ---child
branch11
branch 12
branch 2 ---child
branch 21
branch 3 ----child
branch 31
branch 32
branch 33
here, when i provide input as branch 3, then I need to fetch results branch 2, branch 1 till organization.
can any one help me on this.
Thanks in advance!
Regards,
LKRHi,
Is this the same question as
https://community.oracle.com/thread/2616828
Please don't post the same question over and over. Mark this thread as "Answered" right away, and continue in the other thread (if necessary; the other thread has answers.) -
Write a query for finding STDDEV for OLAP Cube
Can anybody post a sample query which will find the standard deviation of sales for each month in the sample GLOBAL OLAP schema for Oracle 11g.
The OLAP option automatically generates a set of relational views on cubes, dimensions, and hierarchies in Oracle 11g. So how can i write a query for finding the Standard deviation on these views.The easiest way to do this is to do this directly within the AW using a custom calculated measure. In AWM11g you can use the 11g custom measure wrapper to execute the STDDEV function:
olap_dml_expression('function',data type)
For example
olap_dml_expression('STDDEV(cube_name, time_dimension_name)',number)
You can then simply expose this calculated measure as another column in your SQL View and then there is no need to use the SQL equivalent. This means the calculation is performed inside the AW (which is as close to the source data as you can get) ensuring performance of the whole query remains high.
If necessary you can take this a step further, if required, and wrap the STDDEV calculation within an OLAP DML program that would allow you to manipulate the status of time within the calculation. For example, you may want the STDDEV calc to only take into account the last 12 time periods rather than all time periods currently in status.
Hope this helps
Keith Laker
Oracle EMEA Consulting
OLAP Blog: http://oracleOLAP.blogspot.com/
OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
DM Blog: http://oracledmt.blogspot.com/
OWB Blog : http://blogs.oracle.com/warehousebuilder/
OWB Wiki : http://wiki.oracle.com/page/Oracle+Warehouse+Builder
DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html -
How to write a query for the given scenario ?
Hi All ,
I am having two tables EMP, DEPT with the below data.
EMP TABLE :--
EID ENAME JOB SAL DEPID
111 RAM MANAGER 1500 10
222 SAM ASST MANAGER 2000 20
333 KALA CLERK 2500 10
444 BIMA MANAGER 3000 20
555 CHALA MANAGER 3500 30
666 RANI ASST MANAGER 4000 10
777 KAMAL MANAGER 2400 10
DEPT TABLE :--
DEPID DNAME
10 XX
20 YY
30 ZZ
Q1 : I want the sum of salary of each department and for the particular job . Here in each departmant manager, asst. manager, clerk posts are there .
I want to display the result like below ....
JOB 10 20 30
MANAGER 3900 3000 3500
ASST MANAGER 4000 2000 NULL
CLERK 2500 NULL NULL
please tell me how to write a sql query ?
Thanks
SaiIn general case, you cannot write this query.
This is one of the limits of relational database concepts. The number of columns must be known up-front. In the SELECT clause, you have to list and name all columns returned by the query. So you have to know number of departments. (There are some workarounds - you can return one column with concatenated values for all departments, separated by space character).
If you know that you have 3 departments then you qurey will return 4 columns:
SELECT
e.job,
SUM ( CASE WHEN d.deptid = 10 THEN e.sal ELSE NULL END) d10,
SUM ( CASE WHEN d.deptid = 20 THEN e.sal ELSE NULL END) d20,
SUM ( CASE WHEN d.deptid = 30 THEN e.sal ELSE NULL END) d30
FROM dept d, emp e
WHERE d.deptno = e.deptno
GROUP BY e.job -
How to write a query for grouping them the columns and give the sequence order to each group/
Hi i have table that contains country columns .
India,USA,UK like these when ever the group changed into the differt country i make a group and arrange them the sequence into those Countries
like below
1)India
2)India
1)USA
2)USA
like these to write a query ..........pls help me for this queryAssuming you're using SQL Server you can ask here:
http://www.sqlteam.com/forums/forum.asp?FORUM_ID=23
Otherwise, please ask in the relevant forum for the type of technology you're using.
Basically it's either:
select *
from [table name]
order by country
If you want to do something with groups do something like:
select (max) income, country
from [table name]
group by country
Kind regards,
Margriet Bruggeman
Lois & Clark IT Services
web site: http://www.loisandclark.eu
blog: http://www.sharepointdragons.com -
How to write select query for this
Hi,
I had a html form and in the for i had drop down box and it needs to select multiple values from the drop down box. When i select multiple values then i have to write the SQL select statement query .
When i try to write the select statement and trying to run i am getting error.
select * from Table
where emo_no = '1,2,3'
this is how i write query please suggest me how to write query for selecting multiple values from the drop down box.
Thanksselect * from Table
where emo_no in ( 1,2,3)
for integer values
select * from Table
where emo_no in ('1','2','3')
for characters
If we talk about large scale applications that may have millions of records, I would suggest this.
declare @t table (v int)
insert into t (v) values (1)
insert into t (v) valves (2)
insert into t (v) values (3)
select *
from table
inner join @t t on table.emo_no = t.v
Using "in" for a where clause is not so bad for filtering on a few values, but if you are filtering a lot of rows and a lot of values (emo_no) the performance degrades quickly for some reasons beyond the scope of this.
This is just one solution, I'll through this out as well, instead of an in memory (@t) table, doing a disk based temp table (#t) and creating an index on the column "v".
create table #t (v int)
insert into #t (v) values (1)
insert into #t (v) valves (2)
insert into #t (v) values (3)
create index ix_t on #t (v)
select *
from table
inner join #t t on table.emo_no = t.v
drop table #t
Pardon any syntax errors and careful using a drop statement.
Sometimes in memory tables work better than disk temp tables, it takes some testing and trial and error depending on your datasets to determine the best solution.
Probably too much info ;-)
Byron Mann
[email protected]
[email protected]
Software Architect
hosting.com | hostmysite.com
http://www.hostmysite.com/?utm_source=bb -
How to write sql query for below example.
Hi,
I have requirement.
There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
example: table TEST.
COLA COLB COLC COLD
MANAGER 5 NULL null
SR.MANAGE 6 3 NULL
VP 5 5 4
I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
I need output as below.
COLB COLC COLD
5(MANGER) 3(sr.manger) 5(vp)
Please provide the for above mentioned output.
Thanks<<if COLA IS MANAGER THEN CONSIDER MANGER RECORD>>
What does this sentence means? COLA does not cnatin a single record but the number of records with diffrent values.
Regards
Arun -
How to write sql query for below mentioned eaxmple.
Hi,
I have requirement.
There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
example: table TEST.
COLA COLB COLC COLD COLE COLF MANAGER 5 NULL NULL 3 NULL
SR.MANAGER 6 3 NULL NULL NULL
VP 5 5 4 5 5
I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
I need output as below.
COLB COLC COLD COLE COLF
5(manager) 3(sr.manger) 4(vp) 3(manger) 3(vp)
Please provide the for above mentioned output.
ThanksDuplicate thread. please view the answer posted in your first thread.
how to write sql query.
And, please don't post any duplicate thread.
Regards.
Satyaki De. -
How to write a query for the following issue
Hello,
I would like to write a query to display the result in the following format
Item
Categort1
Categort2
Categort3
Categort4
Categort5
Categort6
Min
Max
Avg
Min
Max
Avg
Min
Max
Avg
Min
Max
Avg
Min
Max
Avg
Min
Max
Avg
01
02
03
04
For every item for the category i need to find Min,Max and Avg from the Value column
Table structure is as follows
ID
Item Id
Item
Category
value
1
01
A
Categort1
1
2
01
A
Categort1
2
3
01
A
Categort1
3
4
02
B
Categort2
7
5
02
B
Categort2
8
6
03
C
Categort3
6
7
04
D
Categort4
12
8
04
D
Categort4
14SELECT ItemID,
MIN(CASE WHEN Category = 'Categort1' THEN value END) AS Min_category1,
MAX(CASE WHEN Category = 'Categort1' THEN value END) AS Max_category1,
AVG(CASE WHEN Category = 'Categort1' THEN value END) AS Avg_category1,
MIN(CASE WHEN Category = 'Categort2' THEN value END) AS Min_category2,
MAX(CASE WHEN Category = 'Categort2' THEN value END) AS Max_category2,
AVG(CASE WHEN Category = 'Categort2' THEN value END) AS Avg_category2,
MIN(CASE WHEN Category = 'Categort6' THEN value END) AS Min_category6,
MAX(CASE WHEN Category = 'Categort6' THEN value END) AS Max_category6,
AVG(CASE WHEN Category = 'Categort6' THEN value END) AS Avg_category6
FROM Table
GROUP BY ItemID
The format can be achieved using tools like SSRS
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to write selection Query for the following requirment.
Hi All,
I am new to ABAP, I need a help ,
I need to select all plants(WERKS) from MARC at Plant/Material level,
then I need to take all sales organozation(VKORG) from T001w,
then I need the company code(BUKRS) from TVKO based on VKORG,
then I need the currency key(WAERS) from T001 based on BUKRS,
Can any one help me in writing selection Query for the same?
Thanks All,
Debrup.Hi,
Its easy for you if you learn SELECT with JOIN to complete your task. So SEARCH the forum with SELECT statement and you will get a lot of examples using which you can write your own.
If you struck up anywhere revert back.
Regards
Karthik D -
Help to write a query for cursor
Hi
I have a table trans_table which has records for all Credit (C) and Debit(D) entries for customers with the trans_date.
Now there is a column adj_amt which contains 0 for all D entries. But for C entries it contains current trans_amt - Prev trans_amt. If there is no prev record with C type then it is 0. i.e. If this the first C entry for a particular account then adj_amt will contain 0.
Below is the data.
create table trans_table (cust_id number, tran_date date, tran_amt number, tran_type char(1), adj_amt number);
1 01/01/2007 100 D 0
1 01/01/2007 100 D 0
1 01/02/2007 80 C 0
1 05/02/2007 200 C 120
1 08/02/2007 300 C 100
2 01/01/2007 100 D 0
2 05/01/2007 100 D 0
2 08/01/2007 100 D 0
2 09/01/2007 100 D 0
2 01/02/2007 90 C 0
2 05/02/2007 200 C 110
3 01/01/2007 100 D 0
3 05/01/2007 100 D 0
3 08/01/2007 100 D 0
4 01/01/2007 100 D 0
4 05/01/2007 100 D 0
4 06/01/2007 100 D 0
4 08/01/2007 100 D 0
4 10/01/2007 100 D 0
4 01/02/2007 100 C 0
Now hv to write a query whioch gives the cust_id , max(tran_amt) with D entry, max(trans_amt) wth C entry and if no C entry record then this column will be 0.
The output wud be klike this..
1 100 300
2 100 200
3 100 0
4 100 100
Since cust_id 3 has no C entry so 0 value in 3rd column.
Now i wrote a query for cust_id and 2nd column, but am not able to get the 3rd column.
Is it possible to get the above output..
I wud be using this query in a cursor which wud fetch from 20 million transactions.
Thanks in advance
Piks
(I am pasting the insert script if required)
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('01-02-2007', 'dd-mm-yyyy'), 100, 'C', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('05-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('10-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('08-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (4, to_date('06-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (3, to_date('08-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (3, to_date('05-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (3, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('05-02-2007', 'dd-mm-yyyy'), 200, 'C', 110);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('01-02-2007', 'dd-mm-yyyy'), 90, 'C', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('05-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('09-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (2, to_date('08-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('08-02-2007', 'dd-mm-yyyy'), 300, 'C', 100);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('05-02-2007', 'dd-mm-yyyy'), 200, 'C', 120);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('01-02-2007', 'dd-mm-yyyy'), 80, 'C', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);
insert into TRANS_TABLE (CUST_ID, TRAN_DATE, TRAN_AMT, TRAN_TYPE, ADJ_AMT)
values (1, to_date('01-01-2007', 'dd-mm-yyyy'), 100, 'D', 0);Hitherto an attempt:
test@ORA92>
test@ORA92> select * from trans_table;
CUST_ID TRAN_DATE TRAN_AMT T ADJ_AMT
4 02/01/2007 00:00:00 100 C 0
4 01/05/2007 00:00:00 100 D 0
4 01/01/2007 00:00:00 100 D 0
4 01/10/2007 00:00:00 100 D 0
4 01/08/2007 00:00:00 100 D 0
4 01/06/2007 00:00:00 100 D 0
3 01/08/2007 00:00:00 100 D 0
3 01/05/2007 00:00:00 100 D 0
3 01/01/2007 00:00:00 100 D 0
2 02/05/2007 00:00:00 200 C 110
2 02/01/2007 00:00:00 90 C 0
2 01/05/2007 00:00:00 100 D 0
2 01/01/2007 00:00:00 100 D 0
2 01/09/2007 00:00:00 100 D 0
2 01/08/2007 00:00:00 100 D 0
1 02/08/2007 00:00:00 300 C 100
1 02/05/2007 00:00:00 200 C 120
1 02/01/2007 00:00:00 80 C 0
1 01/01/2007 00:00:00 100 D 0
1 01/01/2007 00:00:00 100 D 0
20 rows selected.
test@ORA92>
test@ORA92> select
2 cust_id,
3 max(case when tran_type = 'D' then tran_amt else 0 end) as max_c,
4 max(case when tran_type = 'C' then tran_amt else 0 end) as max_d
5 from trans_table
6 group by cust_id;
CUST_ID MAX_C MAX_D
1 100 300
2 100 200
3 100 0
4 100 100
4 rows selected.
test@ORA92>
test@ORA92>Cheers
pratz -
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 to write a query for AFTER DATE
Hello Experts,
I’m new to SQL and stuck on a query. How would you write SQL Code for the following query:
The HR Department wants to determine the names of all employees who were hired after Davies:
Thanks in advance.Hello,
You need to change to the table name you have in your schema and in this case its "employees". Don't hard code date in where clause you might have different requirement later ;)
SELECT *
FROM employees
WHERE hire_date > (SELECT hire_date
FROM employees
WHERE name = 'Davies');Regards
Maybe you are looking for
-
I am looking for a App or software to be able to quote jobs,
I have been trying to find a App to be able to do quotes for my Customers with ease. Hope someone can find or help me with this. Mike
-
What is a manufacture warranty of the phone?
Im currently having problems with my z2. The touchscreen is all crazy and non responsive. I tried the repair using sus but it didnt do anything to help. I contacted amazon to see if they could exchange it but since it has passed 30 days since i bough
-
Installing photoshop CS3 on Windows 7
Wondered if anyone else experienced problems installing Photoshop CS3 on Windows 7?
-
I am trying to print unicode characters from my java program to unix console, even though my default file encoding is UTF8, My character is printing garbage. here is my program and the output System.out.println(System.getProperty("file.encoding")); O
-
Export XML in right frame rate for resolve?
Hi! I'm in serious need for some help! When I import my exported XML sequence from premiere in to DaVinci Resolve 10 lite, I get an error message saying "The imported sequence frame rate (25) must be the same as the project frame rate (23,976)." All