How to write a query to get the total as a last row
Hi,
I need to get something like this ....
|TEAM LEADER| TEAM | OCT TRN | EMPS| YTD% |
|_____________|__________|__________|______|_______|
| JOHN | JD Team | 12 | 12 | 100 |
|_____________|__________|__________|______|_______|
| Total | | 12 | 12 | 100 |
|_____________|__________|__________|______|_______|
I have to get the last row as total adding the number columns ...
Thanks in advance ...
Take a look at the GROUP BY ROLLUP feature:
create table t1
(team_name varchar2(30)
,wins number
,losses number
insert into t1 values ('Hornets',3,1);
insert into t1 values ('Panthers',4,0);
insert into t1 values ('Wolves',2,2);
insert into t1 values ('Badgers',0,4);
insert into t1 values ('Hornets',1,3);
commit;
select decode(team_name,
NULL,'TOTAL',
team_name) team_name, sum(wins), sum(losses)
from t1
group by rollup(team_name);
TEAM_NAME SUM(WINS) SUM(LOSSES)
Badgers 0 4
Hornets 4 4
Panthers 4 0
Wolves 2 2
TOTAL 10 10
Similar Messages
-
How to write a query to get the time difference of two varchar type time columns
Hi,
I want to get the time difference between the two varchar type columns.please see the attached image for more details:
My requirement is like:
timestarted
timeended
timediff
9:00:00
10:00:00
1:00
9:15
9:30:00
0:15Storing time alone as VARCHAR2 value is a incorrect design. Always store it as DATE or TIMESTAMP.
If you already have a messed up design and cant change it, then you need to convert your VARCHAR2 time into a DATE or TIMESTAMP and find the difference. I have converted it to TIMESTAMP and obtained the difference as INTERVAL.
SQL> with t
2 as
3 (
4 select '09:00:00' timestarted, '10:00:00' timeended from dual
5 union all
6 select '09:15:00' timestarted, '09:30:00' timeended from dual
7 )
8 select timestarted
9 , timeended
10 , (timeended - timestarted) day to second diff
11 from (
12 select to_timestamp('01011900' || timeended, 'ddmmyyyyhh24:mi:ss') timeended
13 , to_timestamp('01011900' || timestarted, 'ddmmyyyyhh24:mi:ss') timestarted
14 from t
15 );
TIMESTARTED TIMEENDED DIFF
01-JAN-00 09.00.00.000000000 AM 01-JAN-00 10.00.00.000000000 AM +00 01:00:00.000000
01-JAN-00 09.15.00.000000000 AM 01-JAN-00 09.30.00.000000000 AM +00 00:15:00.000000
SQL> -
Please Help!!!
How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column.
January 2014 January
2013 +/-
Region Entry Exit Total Entry Exit Total (Total of Jan2014-Total of Jan2013)
A 2 3
40 5 7 30 40-30= 10What is a table structure? Sorry cannot test it right now..
SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
FROM tbl
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 to modify the query to get the output in a single row
Hi All,
Below is the query i have written it works fine
select DISTINCT right(left(CTACCT,13),4) AS LocationNum,
tODS_GLBalance.FiscalYearId AS FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
--tods_GLMetadata.Metric,
Case when
tods_GLMetadata.Metric = 'Gross Margin'
Then SUM(Balance)
Else 0
END AS GrossMargin,
Case when
tods_GLMetadata.Metric = 'Occupancy'
Then SUM(Balance)
Else 0
END AS Occupancy,
Case when
tods_GLMetadata.Metric = 'Payroll Dollars'
Then SUM(Balance)
Else 0
END AS Payroll,
Case when
tods_GLMetadata.Metric = 'CF Sales'
Then SUM(Balance)
Else 0
END AS OperatingSales,
Case when
tods_GLMetadata.Metric = 'Operations'
Then SUM(Balance)
Else 0
END AS OperatingExpenses
-- 0 as payroll
from ods.[JJill].[tODS_GLBalance]
inner join ods.Staging.tODS_INF_GLPCT ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
inner join ods.JJill.tods_GLMetadata ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
where
(tODS_GLBalance.FiscalYearId = 2012) and
(tODS_GLBalance.FiscalMonthOfYearId = 2) and
(right(left(CTACCT,13),4)= 3020)
group by
right(left(CTACCT,13),4),
tODS_GLBalance.FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId,
tods_GLMetadata.Metric
This is the sample output,
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 0.00 0.00 0.00 0.00
3020 2012 2 0.00 0.00 0.00 -158288.94 0.00
3020 2012 2 0.00 0.00 0.00 0.00 5625.44
3020 2012 2 0.00 0.00 24185.79 0.00 0.00
3020 2012 2 0.00 31075.53 0.00 0.00 0.00
But, i am expecting the output to be something like this
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 31075.53 24185.79 -158288.94 5625.44
Can someone please help me with changing my query to get the desired output?
Please let me know if you have any questions.
ThanksTry this:
SELECT DISTINCT
RIGHT(LEFT(CTACCT,13),4) AS LocationNum, tODS_GLBalance.FiscalYearId AS FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Gross Margin' THEN Balance ELSE 0 END ) AS GrossMargin,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Occupancy' THEN Balance ELSE 0 END ) AS Occupancy,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Payroll Dollars' THEN Balance ELSE 0 END ) AS Payroll,
SUM(CASE WHEN tods_GLMetadata.Metric = 'CF Sales' THEN Balance ELSE 0 END ) AS OperatingSales,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Operations' THEN Balance ELSE 0 END ) AS OperatingExpenses
FROM ods.[JJill].[tODS_GLBalance]
INNER JOIN ods.Staging.tODS_INF_GLPCT
ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
INNER JOIN ods.JJill.tods_GLMetadata
ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
WHERE tODS_GLBalance.FiscalYearId = 2012
AND tODS_GLBalance.FiscalMonthOfYearId = 2
AND RIGHT(LEFT(CTACCT,13),4) = 3020
GROUP BY right(left(CTACCT,13),4), tODS_GLBalance.FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId, tods_GLMetadata.Metric -
How to modify this query to get the desired output format
I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
FROM ALL_CONS_COLUMNS
WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
FROM ALL_CONSTRAINTS AC
WHERE AC.TABLE_NAME=TABLE_NAME
AND AC.TABLE_NAME='&TABLE'
AND AC.R_CONSTRAINT_NAME IS NOT NULL);
This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
For Example I want the output as follows...
TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
EMP DEPTNO DEPT DEPTNO
In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
any help on how to tackle would be appreciated.Try this query
SELECT c.table_name child_table,
c.column_name child_column,
p.table_name parent_table,
p.column_name parent_column
FROM user_constraints a,user_constraints b,user_cons_columns c,
user_cons_columns p
WHERE a.r_constraint_name=b.constraint_name and
a.constraint_name=c.constraint_name and
b.constraint_name=p.constraint_name and
c.position=p.position
ORDER BY c.constraint_name,c.position
Anwar -
How to write SQL query to flatten the hierarchy
Hi,
I have person table which has recursive hierarchy and I wish to flatten it upto 5 levels.
I am using Oracle10g and I have written following query to flatten the hierarchy
SELECT
ID,
level lvl,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 1) AS level_1,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 2) AS level_2,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 3) AS level_3,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 4) AS level_4,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 5) AS level_5
FROM cmt_person
CONNECT BY manager_id = PRIOR id
and level<=5
The person table have more than a million records.
Here I am getting the correct output but this query is taking a lot of time to run.
I am looking at a SQL query without use of connect by to get the required output.
To recreate the issue, you can use this query in HR schema of Oracle and use Employees table.
Any help would be greatly appreciated.
Thanks,
RaghvendraI tried to rewrite the query without using regular expression and connect by. Here is the code:
SELECT
cmt_person.id ,
cmt_person.fname as mgr1,
case when cmt_person2.manager_id=cmt_person.id then (cmt_person2.fname ) end as mgr2,
case when cmt_person3.manager_id=cmt_person2.id then (cmt_person3.fname ) end as mgr3,
case when cmt_person4.manager_id=cmt_person3.id then cmt_person4.fname end as mgr4,
case when cmt_person5.manager_id=cmt_person4.id then cmt_person5.fname end as mgr5
FROM
cmt_person,
cmt_person cmt_person2,
cmt_person cmt_person3,
cmt_person cmt_person4,
cmt_person cmt_person5
WHERE
cmt_person2.manager_id(+)=cmt_person.id and
cmt_person3.manager_id(+)=cmt_person2.id and
cmt_person4.manager_id(+)=cmt_person3.id and
cmt_person5.manager_id(+)=cmt_person4.id
order by 2,3,4
I got following output:
emplo000000000200100 Bobby Khasha Rahul Rajesh
emplo000000000200099 Bobby Khasha Rahul Ajay
emplo000000000200101 Bobby Khasha Rahul Swati
emplo000000000200320 Bobby Khasha Rahul Jinesh
emplo000000000201231 Bobby Khasha Test123
emplo000000000201230 Bobby Khasha User1_Domain
emplo000000000201227 Bobby Khasha User1_World
emplo000000000200104 Bobby Khasha Yitzik Natalia
emplo000000000200103 Bobby Khasha Yitzik Andrew
total 9 rows
But this is partially correct output. I want output like this:
emplo000000000200097 Bobby
emplo000000000200087 Bobby Khasha
emplo000000000200102 Bobby Khasha Yitzik
emplo000000000200103 Bobby Khasha Yitzik Andrew
emplo000000000200104 Bobby Khasha Yitzik Natalia
emplo000000000201227 Bobby Khasha User1_World
emplo000000000201231 Bobby Khasha Test123
emplo000000000201230 Bobby Khasha User1_Domain
emplo000000000200098 Bobby Khasha Rahul
emplo000000000200099 Bobby Khasha Rahul Ajay
emplo000000000200100 Bobby Khasha Rahul Rajesh
emplo000000000200320 Bobby Khasha Rahul Jinesh
emplo000000000200101 Bobby Khasha Rahul Swati
total 13 rows
Do you know what I should do to get this output.
Thanks,
Raghvendra -
How to write a query to get this result?
I have four tables. how to get the result meet the following condition?
1,select all from USERACC_FOR_DOM_REP table.
2,then take out(filter out) the username from EXCEPTION_ACC table where EXCEPTION_ACC.username=USERACC_FOR_DOM_REP.username and
EXCEPTION_ACC.TARGET_DB=USERACC_FOR_DOM_REP.TARGET_DB
3, then take out(filter out) the username from MAX_USER_LOGIN table where MAX_USER_LOGIN.username=USERACC_FOR_DOM_REP.username and
MAX_USER_LOGIN.TARGET_DB=USERACC_FOR_DOM_REP.TARGET_DB and MAX_USER_LOGIN.LAST_LOGIN < sysdate -90).
4, then take out(filter out) the username from MYTABLE table where MYTABLE.username=USERACC_FOR_DOM_REP.username and
MYTABLE.TARGET_DB=USERACC_FOR_DOM_REP.TARGET_DB
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL> desc USERACC_FOR_DOM_REP
Name Null? Type
USERNAME NOT NULL VARCHAR2(30)
ACCOUNT_STATUS NOT NULL VARCHAR2(32)
TARGET_DB VARCHAR2(9)
SQL> desc EXCEPTION_ACC
Name Null? Type
USERNAME NOT NULL VARCHAR2(30)
TARGET_DB VARCHAR2(15)
SQL> desc MAX_USER_LOGIN
Name Null? Type
USERNAME NOT NULL VARCHAR2(30)
TARGET_DB VARCHAR2(9)
LAST_LOGIN DATE
INSERT_DATE DATE
SQL> desc MYTABLE
Name Null? Type
USERNAME VARCHAR2(20)
TARGET_DB VARCHAR2(20)sorry if i didn't make this clear.
here is the problem. i have three tables. like below. i also give some sample data
USERS, USER_MAX_LOGIN, EXCEPTION_USER
USERS table has all the user information for each user in each database.
USER_MAX_LOGIN has those users who logged in within 1 year (we keep 1 year audit data)
EXCEPTION_USER has user which should be excluded from the report.
My report need to find all users in all databases who has not logged in for more than 90 days.
USERS
username target_db profile
u1 d1 user
u2 d1 user
u3 d2 user
u1 d2 user
u2 d2 user
u3 d1 user
USER_MAX_LOGIN
username target_db last_login_date
u1 d1 02-Jan-12
u3 d2 06-Aug-11
u1 d2 06-Aug-11
u2 d2 06-Sep-11
EXCEPTION_USER
username target_db
u2 d1
THIS IS THE REPORT I NEED TO BE LOOK LIKE.
username target_db last_login profile
u3 d2 06-Aug-11 user
u1 d2 06-Aug-11 user
u2 d2 06-Sep-11 user
u3 d1 UNKNOWN user <<----- the unknown means we don't know when the user logged in last time. the user_max_login table does not have its information. -
Write a query to get the users those are not appliyed for the exam?
hi frz i have two tables like User,UserHistory
User table contains clmns--Uid,Uname
UserHistory contain columns--Uid,Course,Status.
so i want to write a query to find out those are not applied for the particlur course i want to found only those records from the two tables...Hello,
The SQL Server forums are over here:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/home
Karl
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
My Blog: Unlock PowerShell
My Book: Windows PowerShell 2.0 Bible
My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}}) -
Query to get the records with same last name
I need to write a single sql query to get all records with duplicate last_name's. For example, if tab1 has 4 records:
10 Amit Kumar
20 Kishore Kumar
30 Sachin Gupta
40 Peter Gabriel
then the query should return
10 Amit Kumar
20 Kishore Kumar
id, name,L_name being the 3 columns in table
Apprecite you help.
Thank you
MarySQL> create table mytable (id,name,l_name)
2 as
3 select 10, 'Amit', 'Kumar' from dual union all
4 select 20, 'Kishore', 'Kumar' from dual union all
5 select 30, 'Sachin', 'Gupta' from dual union all
6 select 40, 'Peter', 'Gabriel' from dual
7 /
Table created.
SQL> select id
2 , name
3 , l_name
4 from ( select t.*
5 , count(*) over (partition by l_name) cnt
6 from mytable t
7 )
8 where cnt > 1
9 /
ID NAME L_NAME
10 Amit Kumar
20 Kishore Kumar
2 rows selected.Regards,
Rob. -
How to run this query to get the minutes between two hours?
Hi all,
Hope doing well,
sir i am running one query which is:
v_TotalHrsMin1 := LPAD((extract(minute from TO_TIMESTAMP (v_Temphrs,'HH24:mi:ss')) - extract(minute from TO_TIMESTAMP (v_Outtime1,'HH24:mi:ss'))), 2, '0');--select to_date(v_temphrs,'YYYY-MM-DD HH:mi:ss')-to_date(v_OutPunch,'YYYY-MM-DD HH:mi:ss')*1440;
in this v_TotalHrsMin1 is number datatype and v_Temphrs is varchar2 which is storing this value: 12:00:00
and v_Outtime1 is varchar2 which is storing 06:00:00
now i want the minute difference between both times
and insert into v_Totalmin1.
but getting null value in v_totalmin1.
thanks952646 wrote:
Hi Sir,
i used query like this: v_TotalHrsMin1 := extract(hour from time_interval) * 60 + extract(minute from time_interval) from (select to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS') time_interval from dual);That is not a query - that is a PL/SQL assignment expression. You should learn the differences between SQL and PL/SQL and how they work together ;-)
When doing it in PL/SQL, you do not need a query at all. Why would you do a select from dual in the PL/SQL assignment.
But you should be able to take the SQL example I gave you and write the equivalent PL/SQL code.
We do not want to do your work for you - we want to teach you how to do it yourself.
You should try and understand the examples we give you - not just cut-and-paste it and cry for help when you are cut-and-pasting a SQL example into PL/SQL code.
Anyway - here's a way to do it in PL/SQL:
declare
v_outtime1 varchar2(8);
v_temphrs varchar2(8);
v_interval interval day to second;
v_totalhrsmin1 number;
begin
v_outtime1 := '06:00:00';
v_temphrs := '12:00:00';
v_interval := to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS');
v_totalhrsmin1 := extract(hour from v_interval) * 60 + extract(minute from v_interval);
end;
/What's so difficult about taking my SQL example, understanding what the differenct functions do, and then write that piece of PL/SQL? ;-) -
How to write select query for all the user tables in database
Can any one tell me how to select the columns from all the user tables in a database
Here I had 3columns as input...
1.phone no
2.memberid
3.sub no.
I have to select call time,record,agn from all the tables in a database...all database tables have the same column names but some may have additional columns..
Eg: select call time, record,agn from ah_t_table where phone no= 6186759765,memberid=j34563298
Query has to execute not only for this table but for all user tables in the database..all tables will start with ah_t
I am trying for this query since 30days...
Help me please....any kind of help is appreciated.....Hi,
user13113704 wrote:
... i need to include the symbol (') for the numbers(values) to get selected..
eg: phone no= '6284056879'To include a single-quote in a string literal, use 2 or them in a row, as shown below.
Starting in Oracle 10, you can also use Q-notation:
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements003.htm#i42617
...and also can you tell me how to execute the output of this script. What front end are you using? If it's SQL*Plus, then you can SPOOL the query to a file, and then execute that file, like this:
-- Suppress SQL*Plus features that interfere with raw output
SET FEEDBACK OFF
SET PAGESIZE 0
-- Run preliminary query to generate main query
SPOOL c:\my_sql_dir\all_ah_t.sql
SELECT 'select call time, record, agn from '
|| owner
|| '.'
|| table_name
|| ' where phone_no = ''6186759765'' and memberid = j34563298'
|| CASE
WHEN ROW_NUMBER () OVER ( ORDER BY owner DESC
, table_name DESC
) = 1
THEN ';'
ELSE ' UNION ALL'
END AS txt
FROM all_tables
WHERE SUBSTR (table_name, 1, 4) = 'AH_T'
ORDER BY owner
, table_name
SPOOL OFF
-- Restore SQL*Plus features that interfere with raw output (if desired)
SET FEEDBACK ON
SET PAGESIZE 50
-- Run main query:
@c:\my_sql_dir\all_ah_t.sql
so that i form a temporary view for this script as a table(or store the result in a temp table) and my problem will be solved..Sorry, I don't understand. What is a "temporary view"? -
How to build a query to get the item properties is tick or not?
hello everybody. i'm 1 of the sap b1 user. i face a problem in build a query to check one of the item properties is tick or not? pls help...
Hi Grace,
your query could look like this:
Select itemcode from oitm where qrygroup1= "Y"
qrygroup1 is item property 1, qrygroup2 is item property 2 etc.
Regards
Ad -
How to get the total amount of filtered row in a table view
I have created filter tables for each columns of my tableview. Now I want to add a row with some totals. For this I use an iterator and implement the RENDER_ROW_START. It is easy to add a new lines knowing the number of expected rows (add the line at the end). But the hic comes when there is a filter. How can I know how many rows I will have in the filtered table. There is no parameters that I found. Not even in an event handler.
Thanks a lot in advance for your helpi found the solution, thanks
-
Query to get the total effort Projectwise
I have the following table
create table Allocation
projID varchar(10),
projName varchar(20),
associateID number,
associateName varchar(10),
allocationStartDate Date,
allocationEndDate Date,
allocationPercent number
PRIMARY KEY(associateID,associateName)
insert into Allocation values ('123','Mr.A','Prj1','Green Computing','to_date('05/15/2011', 'mm/dd//yyyy')','to_date('07/15/2011', 'mm/dd//yyyy')','50');
insert into Allocation values ('123','Mr.A','Prj2','Cloud Computing','to_date('05/31/2011', 'mm/dd//yyyy')','to_date('06/30/2011', 'mm/dd//yyyy')','70');
insert into Allocation values ('1234','Mr.B','Prj1','Green Computing','to_date('06/15/2011', 'mm/dd//yyyy')','to_date('07/31/2011', 'mm/dd//yyyy')','60');
create table Project
projID varchar(10),
projName varchar(20),
StartDate Date,
EndDate Date,
PRIMARY KEY(associateName)
insert into Project values ('Prj1','Green Computing','to_date('05/01/2011', 'mm/dd//yyyy')','to_date('07/31/2011', 'mm/dd//yyyy')');
insert into Project values ('Prj2','Cloud Computing','to_date('05/15/2011', 'mm/dd//yyyy')','to_date('08/31/2011', 'mm/dd//yyyy')');I want to select the project wise efforts. i.e. The number of working days multiplied by the 9hrs for each day for all the associates under a project. The result should look something like this
Project ID Project Name Associate ID Associate Name Effort
Prj1 Green Computing 123 Mr.A 100
Prj1 Green Computing 1234 Mr.B 120Oracle version : 9i 10g/11gI have made my attempt at mind reading (to correct for errors in script). Do you mean the following:
CREATE TABLE Allocation
associateID VARCHAR (10),
associateName VARCHAR (100),
projID VARCHAR (10),
projName VARCHAR (20),
allocationStartDate DATE,
allocationEndDate DATE,
allocationPercent NUMBER,
CONSTRAINT pk_allocation PRIMARY KEY (associateID, ProjID)
INSERT INTO Allocation
VALUES ('123',
'Mr.A',
'Prj1',
'Green Computing',
TO_DATE ('05/15/2011', 'mm/dd/yyyy'),
TO_DATE ('07/15/2011', 'mm/dd/yyyy'),
'50');
INSERT INTO Allocation
VALUES ('123',
'Mr.A',
'Prj2',
'Cloud Computing',
TO_DATE ('05/31/2011', 'mm/dd/yyyy'),
TO_DATE ('06/30/2011', 'mm/dd/yyyy'),
'70');
INSERT INTO Allocation
VALUES ('1234',
'Mr.B',
'Prj1',
'Green Computing',
TO_DATE ('06/15/2011', 'mm/dd/yyyy'),
TO_DATE ('07/31/2011', 'mm/dd/yyyy'),
'60');
COMMIT;
CREATE TABLE Project
projID VARCHAR (10),
projName VARCHAR (20),
StartDate DATE,
EndDate DATE,
CONSTRAINT pk_project PRIMARY KEY (projID)
INSERT INTO Project
VALUES ('Prj1',
'Green Computing',
TO_DATE ('05/01/2011', 'mm/dd/yyyy'),
TO_DATE ('07/31/2011', 'mm/dd/yyyy'));
INSERT INTO Project
VALUES ('Prj2',
'Cloud Computing',
TO_DATE ('05/15/2011', 'mm/dd/yyyy'),
TO_DATE ('08/31/2011', 'mm/dd/yyyy'));
COMMIT;
SELECT a.projid "Project ID",
p.projname "Project Name",
a.associateid "Associate ID",
a.associatename "Associate Name",
CASE
WHEN a.allocationenddate - a.allocationstartdate >= 0
THEN
/*if project begins and ends on the same day,
we still want to allocate 9 hrs,
so we use a "1 + " to account for the first day*/
to_char((1 + (a.allocationenddate - a.allocationstartdate) * 9))
WHEN a.allocationenddate is null or a.allocationstartdate is null
THEN
/*if project is still underway*/
'Project is in progress'
WHEN a.allocationenddate - a.allocationstartdate < 0
THEN
/*begin date is later than end date*/
'Invalid data - begin date must occur before end date'
ELSE
null
END
"Effort"
FROM allocation a
JOIN project p
ON a.projid = p.projid; -
Query to get the data of all the columns in a table except any one column
Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
For Example:
Let us consider the EMP table.,
From this table except the column comm all the remaining columns of the table should be listed
For this we can write a query like this..
Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
Is there any other way of writing the query to get the required result..?
Thanks..Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
If you really need to list all the columns for a table because you don't want to type them, just use something like...
SQL> ed
Wrote file afiedt.buf
1 select trim(',' from sys_connect_by_path(column_name,',')) as columns
2 from (select column_name, row_number() over (order by column_id) as column_id
3 from user_tab_cols
4 where column_name not in ('COMM')
5 and table_name = 'EMP'
6 )
7 where connect_by_isleaf = 1
8 connect by column_id = prior column_id + 1
9* start with column_id = 1
SQL> /
COLUMNS
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
SQL>
Maybe you are looking for
-
Users are not displaying in Management Console's Sessions (AS Java)
Hi, Recently we upgraded our Development Server to EHP 7.11. In SAP Management Console, inside AS Java, when we are trying to view the Sessions, in the User Column the user names are not displaying. Those users are authenticated through UME. Before u
-
Maintain descriptions in other languages for SPRO definitions
Hi, In SPRO, I need to maintain descriptions for Plants and Storage Locations in 2 Other languages apart from EN. Kindly suggest me the solution Best regards
-
Has anyone noticed this with the 1.2C BIOS?
The temperature goes back to normal (dodgy high temps) after flashing the BIOS and cold booting the PC. But after that, if you just go into BIOS as you're booting your PC and then leave by saving to cmos and leaving, the temps are lower again. Happen
-
Hi All Does anyone know if it's possible to view batch numbers of stocked items using XL Reporter? Many thanks Hayden
-
I phone will not "sleep" after non use of 1 hour. How do I fix this?
i phone will not "sleep" after non use of 1 hour. How do I fix this?