SUM two ROWS in the SAME Table
Hi,
I have a problem with this issue. I want to sum two rows from the same table, but I don´t know how to do that. I tried to do it with CTE, but always I get the same error "Ambiguous". I would like to ask you, if there is other manner to get that
data (sum two rows) and if it is possible to see examples about it.
Thank you in advance
Hi Vaibhav,
I leave you my scrip:
USE Modelling
GO
--TABLE Aer_Lingus_Income_Statement
IF OBJECT_ID('Aer_Lingus_Income_Statement') IS NOT NULL
DROP TABLE Aer_Lingus_Income_Statement
GO
CREATE TABLE Aer_Lingus_Income_Statement
ID [nvarchar](255) NOT NULL,
Name_Account [nvarchar](255) NULL,
Company [nvarchar](255) NULL,
Level0_Account [nvarchar](255) NULL,
Level1_Account [nvarchar](255) NULL,
Level2_Account [nvarchar](255) NULL,
Level3_Account [nvarchar](255) NULL,
Level4_Account [nvarchar](255) NULL,
Level5_Account [nvarchar](255) NULL,
Level6_Account [nvarchar](255) NULL,
Level7_Account [nvarchar](255) NULL,
Level8_Account [nvarchar](255) NULL,
Year_2006 decimal (15,2) null,
Year_2007 decimal (15,2) null,
Year_2008 decimal (15,2) null,
Year_2009 decimal (15,2) null,
Year_2010 decimal (15,2) null,
Year_2011 decimal (15,2) null,
Year_2012 decimal (15,2) null,
Year_2013 decimal (15,2) null,
GO
ALTER TABLE Aer_Lingus_Income_Statement
ADD CONSTRAINT PK_Aer_Lingus_Income_Statement PRIMARY KEY (ID)
GO
INSERT INTO Aer_Lingus_Income_Statement
SELECT *
FROM Aer_Lingus_data_Income
IF OBJECT_ID('Aer_Lingus_Income_Statement_Historic') IS NOT NULL
DROP VIEW Aer_Lingus_Income_Statement_Historic
GO
CREATE VIEW Aer_Lingus_Income_Statement_Historic
as
Select Level0_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level0_Account ='Revenue'
Group by Level0_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Passenger revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Ancillary revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Other revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Cargo revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Level0_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level0_Account ='Operating expenses'
Group by Level0_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Staff costs' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Depreciation, amortisation and impairment' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Aircraft operating lease costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Fuel and oil costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Maintenance expenses' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Airport charges' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='En-route charges' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Distribution costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Ground operations, catering and other operating costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Other (gains)/losses - net' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Employee profit share' and Level0_Account ='Operating expenses'
Group by Name_Account
GO
WITH sumasRevenue
AS (
SELECT Name_Account, ID
, sum(Year_2006) AS Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
WHERE Level0_Account = 'Revenue'
GROUP BY Name_Account, ID
WITH ROLLUP
, total
AS (
SELECT Y2006,Y2007 ,Y2008,Y2009 ,Y2010 ,Y2011 ,Y2012 ,Y2013
FROM sumasRevenue
WHERE Name_Account IS NULL
sumasOperatingExpensive
AS (
SELECT Name_Account, ID
, sum(Year_2006) AS Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
WHERE Level0_Account = 'Operating expenses'
GROUP BY Name_Account, ID
WITH ROLLUP
, total1
AS (
SELECT Y2006,Y2007 ,Y2008,Y2009 ,Y2010 ,Y2011 ,Y2012 ,Y2013
FROM sumasOperatingExpensive
WHERE Name_Account IS NULL
SELECT distinct ID , s.Name_Account,
(s.Y2006* 1.0 - t.Y2006) AS [V2006] ,(s.Y2007* 1.0 -T.Y2007 ) as [V2007] , (s.Y2008* 1.0 /T.Y2008 ) as [V2008],(s.Y2009* 1.0 /T.Y2009 ) as [V2009],
(s.Y2010* 1.0 /T.Y2010 ) as [V2010],(s.Y2011* 1.0 /T.Y2011 ) as [V2011],(s.Y2012* 1.0 /T.Y2012 ) as [V2012],(s.Y2013* 1.0 /T.Y2013 ) as [V2013]
FROM sumasRevenue AS s , sumasOperatingExpensive AS t
Where ID IS NOT NULL
UNION ALL
SELECT distinct ID,COALESCE(s.Name_Account,'NON CURRENT ASSETS') AS Name_Account ,
sum (s.Y2006* 1.0 / t.Y2006) as V2006,sum (s.Y2007* 1.0 / t.Y2007) as V2007,sum (s.Y2008* 1.0/ t.Y2008) as V2008,sum (s.Y2009* 1.0/ t.Y2009) as V2009,sum (s.Y2010* 1.0/ t.Y2010) as V2010,
sum (s.Y2011* 1.0 / t.Y2011) as V2011,sum (s.Y2012* 1.0/ t.Y2012) as V2012,sum (s.Y2013* 1.0/ t.Y2013) as V2013
FROM sumasRevenue as s , sumasOperatingExpensive as t
Where ID IS NULL and Name_Account IS NULL
GROUP BY Name_Account, ID
WITH ROLLUP
select *
from Aer_Lingus_Income_Statement_Historic
Thank you in advance
Similar Messages
-
Compare two rows in a same table
Dear all
I need to compare two rows in the same table, I dont know hoe to do it in pl/sql. Some one please help me on this.
example:
tr br price
xya0001 ama7 12
xya0003 ama6 14
xya0004 ama7 16
in the table tr is a unique value for each row, I need to compare price column and see whether the first value is less or greater than the next value and, if it is greater put the corresponding br value to a variable and if it is smaller put the corresponding br value to another variable. I dont know a method to do it, as I'm new to pl/sql. Some one please help me in thisnot sure what you intend to do as you have mentioned that "TR" is unique and you just want to compare each record with just the next record. Hope below query helps. The value "G" or "L" in flag would indicate if the current records price is greater than or less than the price in next record.
select tr,br,price,col4, case when price> col4 then 'G' when price< col4 then 'L' end flag from (
select tr,br,price,lag(price,1,0) over(order by tr) col4 from testcomp
) -
SUM two fileds from different rows from the same table
I would like to SUM two fileds from different rows from the same table but I don't know how to do that.
E.g.
BillingTransactionsIndex CreateDate UserType UserIndex TransType Reference Total Balance
2 6/5/2008 15:02 1 51 1 150 -288.2 -288.2
5 6/8/2008 11:55 1 51 1 157 -1.58674 -289.787
In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance
Please help
ThanksSQL> with tbl as
2 (select 1 as ID, 90 as total from dual
3 union all
4 select 2 as ID, 23 as total from dual
5 union all
6 select 3 as ID, 15 as total from dual
7 union all
8 select 4 as ID, 20 as total from dual)
9 select id , total, sum(total) over (order by ID) as balance from tbl
10 /
ID TOTAL BALANCE
1 90 90
2 23 113
3 15 128
4 20 148
SQL> -
Compare two results from the same table
i have two results from the same table that i would like to compare. below is my query and the results i want to compare
SELECT tblItemRoutingBOM.ItemRevID, tblItem.ItemID, tblItem.PartNum, tblItem.ItemName, tblItem.ManufacturerPartNum AS [Mfg Part#], tblItemRoutingBOM.Quantity
FROM tblItemRouting
INNER JOIN tblItemRoutingBOM ON tblItemRouting.ItemRoutingID = tblItemRoutingBOM.ItemRoutingID
INNER JOIN tblItem ON tblItemRoutingBOM.ItemID = tblItem.ItemID
WHERE tblItemRoutingBOM.ItemRevID in (61,70)
as you can see i am returning two records using the where clause
ItemRevID, ItemID, PartNum, ItemName, Manufacturer, Mfg Part#, Quantity
61,121,331503,.233 Aluminum Sheet,,1
70,121,331503,.233 Aluminum Sheet,,3
now what i am looking for is to combine these two together into one row with the following added. two columns for each QTY, QTY1 = 1 and QTY2 = 3 with a third column added that is the difference between the two QTY Diff = 2
Any thoughts?Here are the two statements that i want to combine, results for each are attached
SELECT tblItem.ItemID, Sum(tblItemRoutingBOM.Quantity) AS SumOfQuantity, tblItem.PartNum AS [Part #],
tblItem.ItemName, tblManufacturer.ManufacturerName AS Manufacturer, tblItem.ManufacturerPartNum AS [Mfg Part#]
FROM tblItemRouting
INNER JOIN tblItemRoutingBOM ON tblItemRouting.ItemRoutingID = tblItemRoutingBOM.ItemRoutingID
INNER JOIN tblItem ON tblItemRoutingBOM.ItemID = tblItem.ItemID
INNER JOIN tblUnits ON tblItem.UnitID = tblUnits.UnitID
LEFT JOIN tblManufacturer ON tblItem.ManufacturerID = tblManufacturer.ManufacturerID
WHERE tblItemRoutingBOM.ItemRevID=61
GROUP BY tblItem.ItemID,tblItem.PartNum,tblItem.ItemName,tblManufacturer.ManufacturerName,tblItem.ManufacturerPartNum
SELECT tblItem.ItemID, Sum(tblItemRoutingBOM.Quantity) AS Quantity, tblItem.PartNum AS [Part #],
tblItem.ItemName, tblManufacturer.ManufacturerName AS Manufacturer, tblItem.ManufacturerPartNum AS [Mfg Part#]
FROM tblItemRouting
INNER JOIN tblItemRoutingBOM ON tblItemRouting.ItemRoutingID = tblItemRoutingBOM.ItemRoutingID
INNER JOIN tblItem ON tblItemRoutingBOM.ItemID = tblItem.ItemID
INNER JOIN tblUnits ON tblItem.UnitID = tblUnits.UnitID
LEFT JOIN tblManufacturer ON tblItem.ManufacturerID = tblManufacturer.ManufacturerID
WHERE tblItemRoutingBOM.ItemRevID=70
GROUP BY tblItem.ItemID,tblItem.PartNum,tblItem.ItemName,tblManufacturer.ManufacturerName,tblItem.ManufacturerPartNum
114,11,55002,Pepsi Blue Cap,NULL,
117,5,331501,Marigold Yellow For ABS,NULL,
121,1,331503,.233 Aluminum Sheet,NULL,
125,2,331504,Velvet Vinyl .008,NULL,
114,33,55002,Pepsi Blue Cap,NULL,
117,15,331501,Marigold Yellow For ABS,NULL,
121,3,331503,.233 Aluminum Sheet,NULL,
125,6,331504,Velvet Vinyl .008,NULL,
my returned result should combine above with two extra columns (two extra columns because i have two results to combine)
114, 11, 33, 22, 55002, Pepsi Blue Cap, NULL,
117, 5, 15, 10, 331501, Marigold Yellow For ABS, NULL
121,1, 3, 2, 331503, .233 Aluminum Sheet, NULL
125, 2, 6, 4, 331504, Velvet Vinyl .008, NULL
Columns go as such, ID, QTY1 (for 61), QTY2 (for 70), Diff (QTY1-QTY2), PartNum, ItemName, Mfg, Mfg Part#
IF the results from one of those two are empty then i would see something like this
114, 11, 0, 11, 55002, Pepsi Blue Cap, NULL,
117, 5, 0, 5, 331501, Marigold Yellow For ABS, NULL
121,1, 0, 1, 331503, .233 Aluminum Sheet, NULL
125, 2, 0, 2, 331504, Velvet Vinyl .008, NULL -
Trigger in mutation - Update another rows in the same table with a trigger
Hi ,
I try to do a before update trigger on a table , but the trigger is in mutation. I understand why it do that but my question is :
How can I update other rows in the same table when a UPDATE is made on my table??????
Here is my trigger :
CREATE OR REPLACE TRIGGER GDE_COMPS_BRU_5 BEFORE
UPDATE OF DEPARTEMENT--, DISCIPLINE, DEG_DEMANDE, CE_ETAB
ON GDEM.COMPOSITION_SUBV
FOR EACH ROW
Organisme : FQRNT-FQRSC
Date de création : 14-07-2011
Date de modification :
Modifié par :
Auteur : Johanne Plamondon
Description : Ce déclencheur s'executera lors de la modification
du responsable dans la table COMPOSITION_SUBV
DECLARE
V_OSUSER V$SESSION.OSUSER%TYPE;
V_PROGRAM V$SESSION.PROGRAM%TYPE;
V_TERMINAL V$SESSION.TERMINAL%TYPE;
V_MACHINE V$SESSION.MACHINE%TYPE;
V_MODULE V$SESSION.MODULE%TYPE;
V_LOGON_TIME V$SESSION.LOGON_TIME%TYPE;
V_AUDIT_ID NUMBER;
vSEQ NUMBER;
i NUMBER;
vID DEMANDE.ID%TYPE;
BEGIN
begin
SELECT OSUSER, PROGRAM, TERMINAL,MACHINE,MODULE, LOGON_TIME
INTO V_OSUSER,V_PROGRAM,V_TERMINAL,V_MACHINE,
V_MODULE,V_LOGON_TIME
FROM V$SESSION
WHERE TYPE = 'USER'
AND USERNAME = USER
AND LAST_CALL_ET IN (0,1)
AND ROWNUM < 2;
exception when others then null; end;
IF NVL(:NEW.SC_PART,' ') = 'CHC' THEN
SELECT COUNT(*)
INTO i
FROM DEMANDE
WHERE DEM_REF = :NEW.DEM_ID
AND PER_NIP = :NEW.PER_NIP;
IF i = 1 THEN
SELECT ID
INTO vID
FROM DEMANDE
WHERE DEM_REF = :NEW.DEM_ID
AND PER_NIP = :NEW.PER_NIP;
UPDATE COMPOSITION_SUBV
SET --CE_ETAB = :NEW.CE_ETAB,
--DISCIPLINE = :NEW.DISCIPLINE,
DEPARTEMENT = :NEW.DEPARTEMENT,
--DEG_DEMANDE = :NEW.DEG_DEMANDE,
DATE_MODIF = SYSDATE,
USER_MODIF = V_OSUSER
WHERE DEM_ID = vID
AND PER_NIP = :NEW.PER_NIP
AND ANNEE = :NEW.ANNEE;
END IF;
END IF;
/*EXCEPTION
WHEN OTHERS THEN
NULL;*/
END;A standard disclaimer, the mutating trigger error is telling you that you really, really, really don't want to be doing this. It generally indicates a major data model problem when you find yourself in a situation where the data in one row of a table depends on the data in another row of that same table. In the vast majority of cases, you're far better off fixing the data model than in working around the problem.
If you are absolutely sure that you cannot fix the data model and must work around the problem, you'll need
- A package with a collection (or global temporary table) to store the keys that are modified
- A before statement trigger that initializes the collection
- A row-level trigger that adds the keys that were updated to the collection
- An after statement trigger that iterates over the data in the collection and updates whatever rows need to be updated.
If you're on 11g, this can be simplified somewhat by using a compound trigger with separate before statement, row-level, and after statement sections.
Obviously, though, this is a substantial increase in complexity over the single trigger you have here. That's one of the reasons that it's generally a bad idea to work around mutating table exceptions.
Justin -
Two triggers in the same table and event
If I created two triggers on the same table and event (before insert), which of them will be triggered first ?...
The problem from the beginning is that I created the second one as after insert and in the body of the trigger I wrote (:new.xxx:= value) ... then an error (that it should be before insert trigger or update trigger), so I created it as before update ,,, but I have already before update trigger (for primary key)..... and the problem -I think- which of them start first...
Can make the second one as after insert and make update statement instead of assigning (:new.xxx:= value).....
RegardsIf I created two triggers on the same table and event
(before insert), which of them will be triggered
first ?...As already mentioned, prior to 11g the order of firing is undetermined.
The problem from the beginning is that I created the
second one as after insert and in the body of the
trigger I wrote (:new.xxx:= value) ... then an error
(that it should be before insert trigger or update
trigger), so I created it as before update ,,, but I
have already before update trigger (for primary
key)..... and the problem -I think- which of them
start first...If there is a conflict of interest inside the code then you will have to alter your design principle around this to cater for it. Also consider combining the code into a single before insert trigger to prevent any confusion.
Can make the second one as after insert and make
update statement instead of assigning (:new.xxx:=
value).....Attempting to update or query the same table as is causing the trigger to fire will result in a mutating table error. You can't do this. -
Hi,
I want to center two different text row that are in the same table but one on the center and the other one on the left. I put a <span> tag hoping that it has been overwhelmed the table's class properties The .bottomsel's font-family and the .Cig84's font-family and colour work but the text-align don't: they're both on the left.
These are my source and CSS codes:
Source:
<table width="600" border="0">
<tr>
<td class="bottomref"><p><span class="bottomsel">| <a href="index.html" target="_self">Main</a> | <a href="about.html" target="_self">About</a> | <a href="clients.html" target="_self">Clients</a> | <a href="contact.html" target="_self">Contact</a> |</span><br />
<span class="credits">Credits: <span class="Cig84">Cig84</span></span></p></td>
</tr>
</table>
CSS:
.bottomsel {
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
.credits {
text-align: left;
.Cig84 {
color: #F00;
font-family: "Comic Sans MS", cursive;Use paragraph tags with CSS classes.
CSS:
.center {text-align:center}
.left {text-align:left}
HTML:
<table width="600" border="0">
<tr>
<td class="bottomref">
<p class="center">This text is center aligned</p>
<p class="left">This text is left aligned</p>
</td>
</tr>
</table>
Nancy O. -
How to sum different column in the same table
Hi everyone
I would like to know how can I make the sum of different column in the same table using apex
exple:
TR_PROJ_BIL_TRIM.ENTPIDFISC as ENTPIDFISC,
TR_PROJ_BIL_TRIM.EXEANNEE as EXEANNEE,
TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV as PROJBILTRIMT1PREV,
TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV as PROJBILTRIMT2PREV,
trunc( TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV)+(TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV)
from TR_PROJ_BIL_TRIM TR_PROJ_BIL_TRIM
group by TR_PROJ_BIL_TRIM.ENTPIDFISC,TR_PROJ_BIL_TRIM.EXEANNEE
but while trying to run this script i get this error message:"ORA-00979: not a GROUP BY expression"
thanks for reading me and I hope to hear from you soonHi,
Your question do not have anything do with APEX.
It is pure SQL question and you will get better answer this kind questions from SQL and PL/SQL forum
You need have GROUP BY when you use aggregate functions like SUM.
I assume you like just add two columns.
Try
SELECT ENTPIDFISC
,EXEANNEE
,PROJBILTRIMT1PREV
,PROJBILTRIMT2PREV
,trunc(PROJBILTRIMT1PREV) + (PROJBILTRIMT2PREV)
FROM TR_PROJ_BIL_TRIM
Regards,
Jari -
Persistence two beans in the same table, Duplicate table name in different beans
Hi,
I need to persist two beans belonging to different classes in the same
table, but the following mistake happens:
[jdo-enhance] javax.jdo.JDOFatalUserException: Invalid jdbc-table-name:
Duplicate table name
There exists some way of persisting both objects in the same table?
thanks
jasabinoNo. It would be very confusing to do so. Can they not share an
inheritance hierarchy? You can use flat mapping to do so.
Jose wrote:
Hi,
I need to persist two beans belonging to different classes in the same
table, but the following mistake happens:
[jdo-enhance] javax.jdo.JDOFatalUserException: Invalid jdbc-table-name:
Duplicate table name
There exists some way of persisting both objects in the same table?
thanks
jasabino -
Calculating average time from two records from the same table.
Hi all
I need to calculate the average time between two events that are recorded in the same table.
The table is TMS_MESSAGE_AUDIT_LOG
MESSAGE_ID VARCHAR2(16 BYTE) NOT NULL,
MESSAGE_VERSION NUMBER(2) NOT NULL,
CREATE_TM VARCHAR2(18 BYTE) NOT NULL,
MESSAGE_STATUS VARCHAR2(30 BYTE),
TRANSACTION_TYPE_NM VARCHAR2(30 BYTE),
MESSAGE_TP VARCHAR2(3 BYTE),
WORKFLOW_OBJECT VARCHAR2(30 BYTE) NOT NULL,
WORKFLOW_REQUEST VARCHAR2(30 BYTE) NOT NULL,
WORKFLOW_RETURN_CD VARCHAR2(30 BYTE) NOT NULL,
AUDIT_ACTION VARCHAR2(255 BYTE),
LAST_UPDATE_USER_LOGON_ID VARCHAR2(12 BYTE),
LOCAL_TM VARCHAR2(18 BYTE) NOT NULL,
LOCAL_TIME_ZN_NM VARCHAR2(70 BYTE) NOT NULL,
LOCAL_DAYLIGHT_IN CHAR(1 BYTE) NOT NULL,
FPRINT VARCHAR2(30 BYTE)
What i now need is
When the MESSAGE_ID is the same i need have the average time between when the MESSAGE_STATUS is AA and BB ( I need the time out of the CREATE_TM field )
And this for every 15 minutes interval.
Because this table will become BIG millions and millions of records it needs to be fast.
Can anybody help me.
MarcelSomething like this?
CREATE TABLE wr_test
( message_id VARCHAR2(16 BYTE) NOT NULL
, message_version NUMBER(2) NOT NULL -- Assumption: Acknowledged ver > Received ver
, create_tm VARCHAR2(18 BYTE) NOT NULL
, message_status VARCHAR2(30 BYTE)
, transaction_type_nm VARCHAR2(30 BYTE)
, workflow_object VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
, workflow_request VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
, workflow_return_cd VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
, audit_action VARCHAR2(255 BYTE)
, last_update_user_logon_id VARCHAR2(12 BYTE)
, local_tm VARCHAR2(18 BYTE) NOT NULL
, local_time_zn_nm VARCHAR2(70 BYTE) DEFAULT 'GMT' NOT NULL
, local_daylight_in CHAR(1 BYTE) DEFAULT 'x' NOT NULL );
INSERT ALL
INTO wr_test
( message_id
, message_version
, create_tm
, message_status
, local_tm )
VALUES ( message_id
, 1
, create_tm
, '(Receive)'
, TO_CHAR(local_tm,'YYYYMMDD HH24:MI:SS') )
INTO wr_test
( message_id
, message_version
, create_tm
, message_status
, local_tm )
VALUES ( message_id
, 2
, create_tm
, 'Wait CLSB Ack'
, TO_CHAR
( local_tm + NUMTODSINTERVAL(DBMS_RANDOM.VALUE(0,2e5),'SECOND')
, 'YYYYMMDD HH24:MI:SS' ) )
SELECT ROWNUM AS message_id
, TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS create_tm
, DATE '2000-01-01' + DBMS_RANDOM.VALUE(0,3) AS local_tm
FROM dual CONNECT BY ROWNUM < 100000;
WITH src AS
( SELECT message_id
, message_status
, message_version
, TO_DATE(SUBSTR(local_tm,1,17),'YYYYMMDD HH24:MI:SS') AS dt
, TO_DATE(SUBSTR(local_tm,1,8),'YYYYMMDD') AS dt_day
, TO_CHAR(TO_DATE(SUBSTR(local_tm,10,8),'HH24:MI:SS'),'SSSSS') AS dt_sec
FROM wr_test
WHERE message_status IN ('(Receive)','Wait CLSB Ack') )
SELECT dt_day + NUMTODSINTERVAL(period,'SECOND') AS dt
, NUMTODSINTERVAL(AVG(elapsed),'DAY') AS avg_elapsed
, NUMTODSINTERVAL(MIN(elapsed),'DAY') AS min_elapsed
, NUMTODSINTERVAL(MAX(elapsed),'DAY') AS max_elapsed
, COUNT(*)
FROM ( SELECT message_id
, message_status
, dt_day
, TRUNC(dt_sec/300)*300 AS period
, LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) AS ack_dt
, LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) - dt AS elapsed
FROM src ) cal
WHERE cal.message_status = '(Receive)'
GROUP BY dt_day, period
ORDER BY 1;Replace "wr_test" with "tms_message_audit_log" in the WITH subquery to test on your data. -
How to compare two fields from the same table in the select statement
Hi, friends
I try to compare tow fields from the same table, but no result,
For example, this
data: cptotchek tyep i.
select count(*) into cptotchek
from aufk where erdat = aufk-idat2 .
The result is cptotchek = 0, but there are the records in aufk , where, aufk-erdat = aufk-idat2.
Please, help me, i don't use the loop statement for optimize my program.
RegardsHi ,
it will not return any value when you are using column of same table
such as Date Field , Because while Using Aggregate Function it will not check with self column
. For that you have to take data in one internal table and then you can work on it .
And if you are worried about Performance it will not affect , untill you are selecting only required data .
you can try this way .
data: cptotchek type i.
types : begin of w_aufk.
include structure aufk .
types : end of w_aufk .
data : it_aufk type standard table of w_aufk with header line .
select * into corresponding fields of table it_aufk
from aufk .
loop at it_aufk .
if it_aufk-erdat = it_aufk-idat2 .
write : / it_aufk-erdat , it_aufk-idat2 .
else .
delete it_aufk .
endif .
endloop.
Regards
Deepak. -
Hi people,
Since i guess this is a pretty common question, i did make a search in the forum and Google. I did not find the way to have 2 Headers in the same table.
I have a 4 pages long table. The same Header is quite useful in the first 2 pages but not in the last one and for design purposes (autoflow) is nice to have a long table not broken in smaller ones. I mean than in the last 2 pages i would need a different Header than the initial one.
Any idea?
THanks and cheers,
Sebastian>does your script [will] work on CS3 and Mac?
You mean the tagged text? (I see now I accidentally called it "INX" -- that's something else.) Yes, it's compatible all the way down to CS, but since it describes Javascript objects for CS4 only, the textual contents are of limited usefulness for CS3. However, you can inspect the document to see how to do the table trick.
Create a new, empty InDesign document, preferably of A4 size (as the tables are designed to fit). "Place" the tagged text document as usual -- ID should tell you it's placing tagged text. From then on, wait (and wait and wait some more -- it's about 800 pages) until ID has digested the massive chunk. Then you should get a lot of colorful pages! Click inside any table and, using Table Setup, inspect the Header/Footer tab field. If you deselect "Skip First Header" and "Skip Last Footer", you can see them on every page. Selecting these again hides the first ('continued') and last ('continued from last page') occurrences again. -
Subtracting two rows from the same column
Hi,
I have the following table with about 6000 rows of different year_month but I am compare and subtract v
Organization Year_month Contribution
Kano JAN-2011 200000
KADUNA JAN-2011 300000
ABUJA JAN-2011 400000
Kano FEB-2011 300000
KADUNA FEB-2011 200000
ABUJA FEB-2012 600000
I want to select a year_month at run time to subtract the contribution of the first year_month from the contribution of the second year_month and give me the result as shown in the following table
Organization JAN-2011 FEB-2011 diffrence
Kano 200000 300000 -100000
KADUNA 300000 200000 100000
ABUJA 400000 600000 -200000
Here is my code returning too many va
create or replace function "GET_MONTHLY_VALUE"
(q_name in VARCHAR2,
hmoCode in VARCHAR2)
return VARCHAR2
is
c1 number;
begin
select NHIS_CONTRIBUTION into c1 from CONTRIBUTION_MGT where upper(YEAR_MONTH)=upper(q_name) and upper(ORGANIZATION)=upper(hmoCode);
return c1;
exception when NO_DATA_FOUND THEN
return null;
end;
------a call to the above function:
create or replace function process_cont_monthly return varchar
is
Cursor cont_cursor is select ORGANIZATION from CONTRIBUTION_MGT;
begin
for
cont_rec in cont_cursor loop
select GET_MONTHLY_VALUE(:p26_month,cont_rec.ORGANIZATION) first, GET_MONTHLY_VALUE(:p26_month2,cont_rec.ORGANIZATION) second,
abs(GET_MONTHLY_VALUE(:p26_month,cont_rec.ORGANIZATION)-GET_MONTHLY_VALUE(:p26_month2,cont_rec.ORGANIZATION)) Diffrence
from CONTRIBUTION_MGT;
end loop;
commit;
end;
I became totally confused and don’t know what to do next
Any help and better guide is appreciatedHi,
Here's one way:
WITH months_wanted AS
SELECT 1 AS col, TO_DATE ('JAN-2011', 'MON-YYYY') AS month FROM dual
UNION ALL
SELECT 2 AS col, TO_DATE ('FEB-2011', 'MON-YYYY') AS month FROM dual
, pivoted_data AS
SELECT c.organization
, NVL (SUM (CASE WHEN m.col = 1 THEN c.contribution END), 0) AS total_1
, NVL (SUM (CASE WHEN m.col = 2 THEN c.contribution END), 0) AS total_2
FROM months_wanted m
JOIN contribution_mgt c ON c.year_month >= m.month
AND c.year_month < ADD_MONTHS (m.month, 1)
SELECT organization
, total_1
, total_2
, total_1 - total_2 AS difference
FROM pivoted_data
ORDER BY organization
;I assume that the year_month column is a DATE. Date information always belongs in DATE columns.
As written, the two months do not need to be consecutive. If you always want consectuive months, this can be re-written so that you only have to enter the first month, not both of them.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Point out a few places where the query above is giving the wrong results, and explain, using specific examples, how you get those results from that data in those places. If you changed the query at all, post your code.
Always say which version of Oracle you're using.
See the forum FAQ {message:id=9360002} -
Display two rows at the same time
Hi,
How can I show on page two rows (same iterator) at the same time.
I can create on page input attributes and than in backing bean create two rows for iterator when I inserting data.
(or when showing data get two rows from iterator in backing bean and set value for input attributes)
Is there another way?
AndrejaBoth. To show and create.
I'm using ADF Web Services and I call method with array parametar.
User have to create two record using form (not table) and records must be visible at the same time.
I'm calling method that return array with two records, too.
I can show both record in table but I have to display them using form.
Andreja -
Two records from the same table in for loop
I have a table that holds teams, a table that holds scores and a table that holds match data.
I am finding it dificult to get the player data for the second team.
Currently It is showing player information for one team.
It does echo out the second team name, but not their player info.
Can someone have a look at my code and make it work.
I took off the code I had for the second team becuase it was ging me Error 1065
Main Query:
mysql_select_db($database_db, $db);
$query_match_fixtures = "select m.match_id, date_format(m.date, '%d/%m/%Y') as mDate, m.time, t1.division, m.report, t1.team_name as team1_name, s1.score as score1, t2.team_name as team2_name, s2.score as score2
from matches m left join (matchscores s1 left join team t1 on t1.team_id = s1.team) on (s1.match_id = m.match_id) left join (matchscores s2 left join team t2 on t2.team_id = s2.team) on (s2.match_id = m.match_id)
where s1.team <> s2.team AND m.match_id = $matchID
group by match_id
order by m.match_id";
$match_fixtures = mysql_query($query_match_fixtures, $db) or die(mysql_error());
//$row_match_fixtures = mysql_fetch_assoc($match_fixtures);
$totalRows_match_fixtures = mysql_num_rows($match_fixtures);
Player extraction:
mysql_select_db($database_db, $db);
$row_match_player = array();
for ($i = 0; $i < $totalRows_history; $i++)
$row_history[$i] = mysql_fetch_assoc($history);
for ($i = 0; $i < $totalRows_match_fixtures; $i++)
$row_match_fixtures[$i] = mysql_fetch_assoc($match_fixtures);
$match_player_query = "SELECT *
FROM match_player
LEFT JOIN player on player.player_id = match_player.player_id
LEFT JOIN team ON player.team_id = team.team_id
WHERE match_id = ".$matchID."
AND team.team_name = '".$row_match_fixtures[$i]['team1_name']."'";
$result_match_player = mysql_query($match_player_query, $db) or die("large error ".mysql_errno());
$totalRows_match_player = mysql_num_rows($result_match_player);
for ($r; $r < $totalRows_match_player; $r++)
$temp_row_match_player[$r] = mysql_fetch_assoc($result_match_player);
array_push($row_match_player, $temp_row_match_player);
The display table:
<div class="tableHeading">
<h2><?php echo $row_history['mDate']; ?></h2>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" bgcolor="#000000"><div align="left" style="color:#FFFFFF"><strong>Type</strong></div></td>
<td height="25" bgcolor="#000000"><div align="left" style="color:#FFFFFF"><strong>Home</strong></div></td>
<td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Score</strong></div></td>
<td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Away</strong></div></td>
<td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Kick-Off</strong></div></td>
<td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Venue</strong></div></td>
<td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Referee</strong></div></td>
</tr>
<tr>
<?php foreach ($row_match_fixtures as $show_match_fixtures)
{ ?>
<td height="25" bgcolor="#dfdfdf">
<div align="left"><?php echo $show_match_fixtures['division']; ?></div>
</td>
<td height="25" bgcolor="#dfdfdf">
<div align="left"><?php echo $show_match_fixtures['team1_name']; ?></div>
</td>
<td height="25" bgcolor="#dfdfdf">
<div align="center"><?php echo $show_match_fixtures['score1']; ?> - <?php echo $show_match_fixtures['score2']; ?></div>
</td>
<td height="25" bgcolor="#dfdfdf">
<div align="center"><?php echo $show_match_fixtures['team2_name']; ?></div>
</td>
<td height="25" bgcolor="#dfdfdf">
<!-- You do not want a nested loop inside the header so these results will have to go inside the table-->
<div align="center"><?php echo $row_history['time']; ?></div>
</td>
<td height="25" bgcolor="#dfdfdf">
<div align="center"><?php echo $row_history['venue_name']; ?></div>
</td>
<td height="25" bgcolor="#dfdfdf">
<div align="center"><?php echo $row_history['fname']; ?> <?php echo $row_history['sname']; ?></div>
</td>
</tr>
<tr>
<?php foreach ($row_match_player as $player_array)
foreach ($player_array as $player_display)
?>
<td valign="top">Goalscorers</td>
<td>
<?php echo $player_display['fname']." ".$player_display['sname']." (".$player_display['Goals']; ?>)<br />
</td>
<td> </td>
<td>
<?php echo $player_display['fname']." ".$player_display['sname']." (".$player_display['Goals']; ?>)<br />
</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td valign="top">Yellow Cards</td>
<td><?php echo $player_display['YC']; ?></td>
<td> </td>
<td><?php echo $player_display['YC']; ?></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td valign="top">Red Cards</td>
<td><?php echo $player_display['RC']; ?></td>
<td> </td>
<td><?php echo $player_display['RC']; ?></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td valign="top">Man of the Match</td>
<td><?php echo $player_display['fname']; ?> <?php echo $player_display['sname']; ?></td>
<td> </td>
<td><?php echo $player_display['fname']; ?> <?php echo $player_display['sname']; ?></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
}// close and unset $player_display
unset($player_display);
} //close and unset $player_array
unset($player_array);
} //close and unset $show_match_fixtures
unset($show_match_fixtures);?>
</table>
As you can see from the picture above the table is displayed with the name of the "goal scorer" for that team under (home) or Home team
When I try to create the same thing for away team I get a error, either a syntax error or 1065.
I tried having a foreach do two queries but that did not work.
Any help would be appriecatedI did try that, but I have messed it up.
Now the team names do not display at the top of the table.
Maybe you are looking for
-
Looking for a way to save space on iphone and maintain music in itunes
Okay here is the problem, I own a macbook pro and a iphone 16gb and I have been using itunes to manage my music for a very long time and my library has grown into thousands of songs. Now, Is there a way to convert my music down to fit more on my ipho
-
Why is Illustrator CS4 so ******* sluggish in OSX?
I always used Illustrator on Windows XP but have been forced to work on Illustrator on OSX (Imac dual core 3 Ghz with 4GB of ram OSX 10.5.8) at work for the last year. I like OSX but Illustrator performance is quite bad compared to what I'm used to o
-
Can I get a list of users who have a specific authorization role?
Hello, I'm wondering if there is a BAPI or FM that takes as input a single authorization role and gives me back a list of all users who have that role? Thx. Andy Jacobs
-
In SQL Server, there is a GUID datatype that we use in our replication. However, we need to determine the feasibility of Oracle as a back end for some customers. In this case, we need to be able to store the GUIDs as we currently do and also allow th
-
I just updated my Firefox web browser to version 15.0 on my MacBook. I am really used to have Tabs under Address Bar. However, when I Control-click on an empty section of the Tab Strip, there is no "Tabs on Top" option in the pop-up menu. Any suggest