Combine Two table columns
SELECT providerid, SUM(COUNT) FROM appdev.usercounts
WHERE counttime BETWEEN SYSDATE - 30/1440 AND SYSDATE- 15/1440 GROUP BY providerid ORDER BY providerid
W 697
U 813
T 143
S 2
SELECT providerid, SUM(COUNT) FROM appdev.usercounts
WHERE counttime BETWEEN (SYSDATE -1) - 30/1440 AND (SYSDATE-1)- 15/1440 GROUP BY providerid ORDER BY providerid;
W 450
U 571
T 80
S 2
I wnat output as like
W 697 450
U 813 571
T 143 80
S 2 2
please help
Thanks
Praveen
"COUNT", is that the real column name? It could become very confusing.
Not tested for obvious reasons, but this should be close :
SELECT providerid
, sum(
case when counttime between sysdate - 30/1440 and sysdate - 15/1440 then count end
) as cnt1
, sum(
case when counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 then count end
) as cnt2
FROM appdev.usercounts
WHERE ( counttime between sysdate - 30/1440 and sysdate - 15/1440 )
OR ( counttime between (sysdate-1) - 30/1440 and (sysdate-1) - 15/1440 )
GROUP BY providerid
ORDER BY providerid
;
Similar Messages
-
Combining two tables without any distinct columns between them
Folks,
Hi sidy2j,
According to your description, we need to verify your table structures, and the actual results which you want to get from your tables. Please post more information for analysis.
Assume, if you want to a one to one record mapping between two tables without any common column between them for joining, you can refer to the following scripts to implement your requirement. For more information, see:
http://sqlhints.com/2013/09/07/joining-two-tables-without-any-common-column-between-them-sql-server/
If you want to match every row in the first table with every row in the second table, you can refer to the following detail.
http://stackoverflow.com/questions/1198124/combine-two-tables-that-have-no-common-fields
Hope it can help you.
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support -
Fast ESP Combining two navigator columns in index profile
Can we union or combine two Navigators columns result in one column using index profile or FQL?
For example:I have 2 navigators ,KBReleasesNav (refers field KBReleases) and DOCrealeasesNav( refers DOCreleases).there are some common releases in both.I want to show these as one navigator and count as sum of both in UI.I don't think is possible out of the box. May be some kind of customization can do it.
-
hi all,
i am using db10g.
my task is to compare two table's data for example
table1 is having
col1 col2 col3
a b c
e f g
table2 is
col4 col5 col6
a e c
e f g
so i have to compare col1 first record and col4 first record.
in otherwords first table first column first item with second table first table first value and so on.
for ex: a= a
b= e
c= c etc
how can i acheive this?
both are database tables.
i cannot use minus function because data types are different for the corresponding column
how can i compare it?
Thanks..
Edited by: user13329002 on Jan 13, 2011 1:09 AMHi,
Try this
select
case
when a.col1 = b.col1 then 'EQUAL' else 'NOT EQUAL' end column1,
case
when a.col2 = b.col2 then 'EQUAL' else 'NOT EQUAL' end column2,
case
when a.col3 = b.col3 then 'EQUAL' else 'NOT EQUAL' end column3
from (select col1,col2,col3,rownum rn from table1) a,
(select col1,col2,col3,rownum rn from table2) b where a.rn = b.rn Try to see how you order the rows of the two tables.
cheers
VT -
Combine two tables without common field
Hi Experts,
I have two database tables, DBSTATORA(stores inform about all the tables involved in infoproviders), and RSDODSO ( stores information about ODS Objects. I have to list the ods objects and its associated tables as the output, but there is no common field in these two tables how will i combine these two tables, can anyone please suggest me. Any help will be fine.
thanks,
Prabhu.Hi Everyone,
I know the ods tables names are stored like /bix/a<ods_name>00 and /bix/a<ods_name>40 and for change log it is /bic/b*. But my requirement is I have to display the size of the tables belonging to a particular ods object. So for all the tables the size is stored in DBSTATTORA which gives information about
DBSTATTORA
fields of this tables are:
TNAME --> Table Name
ANDAT --> Analyzing Date
AMETH --> Analysis method for collecting Statistics
NROWS --> No of rows in a table
OCCBL --> Used blk(size) of table in KB
EMPBL --> Empty blk(size) of table in KB
AFREE --> Avg Freespace in a used db block
INDBS --> Used Blk(size) of an index kb
This is a table which stores the statistics information.
It displays all the tables of infocubes and ods objects, but does tell that this table belongs to this infoprovider.
I have to display data from this table as well as the infoprovider to which it belongs. So there is no proper information of database tables where the infocube and its associated tables like the facttable, dimtables are stored together. Same for the ods objects also.
There are for ods object RSDODSOTABL which give information about ods object and the table name is stored differently <ods_name>_0000. How do i map this table with the DBSTATTORA table, the tablenames doesn't match. Same problem with RSTSODS table which give informaiton about change log table.
And also for infocubes, there is RSDCUBE which gives information about infocubes but not the associated tables. So does anyone know where all these information is stored in some database tables. It would be of great help.
Thanks a lot.
Prab -
Hi
Using below sql get the columns discrepncy .I want to display the discprency of columns from two tables in form of flat file using pl/sql.
select col1,col2 from A
minus
select * from B -- Rows in A that are not in B
union all
select col1,col2 from B
minus
select col1,col2 from A ----- rows in B that are not in A
Thanksin advance
MRHi
Wrote the cursor for this ,I am not getting expected o/p .Please any help
DECLARE
CURSOR C1 IS SELECT ACCOUNT_CUST_CD , account_contact_person_cd
FROM account where ACCOUNT_CUST_CD='1-411FQ'
AND account_contact_person_cd IS NOT NULL ORDER BY account_contact_person_cd ;
CURSOR C2 IS SELECT ACCOUNT_CUST_CD , account_contact_person_cd FROM bill_bkp
where ACCOUNT_CUST_CD='1-411FQ'AND ACCOUNT_STATUS_DESC='Blacklisted Customer'ORDER BY account_contact_person_cd ;
BEGIN
FOR REC1 IN C1
LOOP
FOR REC2 IN C2
LOOP
IF REC1.account_contact_person_cd <> REC2.account_contact_person_cd or
REC1.ACCOUNT_CUST_CD<>REC2.ACCOUNT_CUST_CD
THEN
DBMS_OUTPUT.PUT_LINE(REC1.account_contact_person_cd||REC2.account_contact_person_cd||REC1.ACCOUNT_CUST_CD||REC2.ACCOUNT_CUST_CD);
END IF;
END LOOP;
END LOOP;
END;
Thanks and Regards,
MR -
Combining two tables into one result
Hi all, I am fairly inexperienced with Crystal but have gained good results from the reports I have created, I am fluent in SQL and Basic to an extent. I am interigating a Pronto database and I want concatenate two tables into one report.
Table One: Customer Orders
Fields: Customer No, Invoice Number, Invoice date, Invoice Amount, Cost Amount.
Table Two: Archived Customer Orders
Fields: Customer No, Invoice Number, Invoice date, Invoice Amount, Cost Amount.
I want to complete a report that will tell me the sales for a given period and the outstanding orders for each customer total for all fields in each table combined into one figure.
Any help would be greatly appreciated.
Thanks in advanceHi Grant,
As you said you are goot at writing SQL, in Crystal write a SQL statement in Add Command to join both table using Union / Union all
If you use Union then it will filter duplicate records and pull the data from database, If you use Union All then it will include all your duplicate records. Please use Union / Union All as required.
Once you get all data into the report create a parameter for date range and generate the summaries as required.
Thanks,
Sastry -
Question about combining two tables
I have two tables that I want to combine them together:
Table A: ID x
49 3
127 1
Table B: ID y
49 1
83 2
127 1
Expected combined table C: ID x y
49 3 1
83 0 2
127 1 1
Seems I have to do two out join and them union them together. Any better ways?
Thanks
garyThe tables are not displayed properly. try it again:Use the {noformat}{noformat} tag for that.
Put it before and after your example.
So, when you type or paste your formatted code like this:
{noformat}select *
from dual;{noformat}
it will appear as:select *
from dual;on this forum -
I have the following two tables:
Asset_Issued
Asset_Type_ID
Assigned To
1
Ram
2
Ram
3
Ram
4
Ram
5
Ram
1
Raju
3
Raju
5
Raju
1
Rajesh
3
Rajesh
2
Rajesh
Asset_Type
Asset_Type_ID
Asset_Name
1
Laptop
2
Desktop
3
Mouse
4
Keyboard
5
Monitor
Can anyone help me with the query that will give the following result.
Asset_Issued_Count
Asset_Name
Count
Laptop
3
Desktop
2
Mouse
3
Keyboard
1
Monitor
1I think your OUTPUT COUNT for MONITOR should be 2 and not 1. Try the below.
WITH ASSET_ISSED(ASSET_TYPE_ID,ASSIGNED_TO) AS(
SELECT 1,'Ram' FROM DUAL UNION ALL
SELECT 2,'Ram' FROM DUAL UNION ALL
SELECT 3,'Ram' FROM DUAL UNION ALL
SELECT 4,'Ram' FROM DUAL UNION ALL
SELECT 5,'Ram' FROM DUAL UNION ALL
SELECT 1,'Raju' FROM DUAL UNION ALL
SELECT 3,'Raju' FROM DUAL UNION ALL
SELECT 5,'Raju' FROM DUAL UNION ALL
SELECT 1,'Rajesh' FROM DUAL UNION ALL
SELECT 3,'Rajesh' FROM DUAL UNION ALL
SELECT 2,'Rajesh' FROM DUAL),
ASSET_TYPE(ASSET_TYPE_ID,ASSET_NAME) AS
(SELECT 1,'Laptop' FROM DUAL UNION ALL
SELECT 2,'Desktop' FROM DUAL UNION ALL
SELECT 3,'Mouse' FROM DUAL UNION ALL
SELECT 4,'Keyboard' FROM DUAL UNION ALL
SELECT 5,'Monitor' FROM DUAL)
SELECT ASSET_NAME,
COUNT(1)
FROM
ASSET_ISSED T1,
ASSET_TYPE T2
WHERE T1.ASSET_TYPE_ID=T2.ASSET_TYPE_ID
GROUP BY T2.ASSET_NAME;
OUTPUT:
ASSET_NA COUNT(1)
Desktop 2
Laptop 3
Mouse 3
Keyboard 1
Monitor 2 -
I need to combine two Excel columns into one.
Specifically I've exported a .csv file from another web app and it has First Names and Last Names in separate columns. I need them combined into a single column which includes both first and last names. I can't seem to remember how to get it come without the delimiter. I've already had to specify which columns to "skip" and other things in the dialogue box brought up when I "Get external data." Any way to do this cleanly?
Thanks in advance,
DanEasiest way, when already in Excel, is to use the CONCANTENATE function in a new column that will then have the combined text of the separate columns...
For example column A has the first name and column B has the last name...
use the following formula in any empty column cell: =CONCANTENATE(A1, " ", B1)
(note added the literal space surrounded by quotes as thats how you would normally see the names.
then you select and copy the formula of the cell (Cmd-C), then select/highlight the rest of the column and paste (Cmd-V) and you're done. -
Hello,
What I want to do is very simple: I have a read-only table, displaying a product price and its quantity. I want a third column in which I could display the total price.
I tried #{row.SalesPrice*row.Quantity} but I had this exception:
Attempt to coerce a value of type "oracle.jbo.domain.Number" to type "java.lang.Long"
So I tried : #{row.SalesPrice.multiply(row.Quantity)}
But now I have javax.faces.el.ReferenceSyntaxException: row.SalesPrice.multiply(row.Quantity)
Do you know what is the correct expression?
Thanks,
Romainyou can use a convertNumber
I guess your using an output text? put the following code inside it:
<f:convertNumber groupingUsed="false"/>
<af:outputText value="#{bindings.<yourattr>}">
<f:convertNumber groupingUsed="false"/>
</af:outputText> -
hi,
Does anyone have or can show me the principle of a such kind of function ?see
http://geekswithblogs.net/leonardm/archive/2010/01/14/table-schema-comparison-in-sql-server.aspx
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Hi there,
It might be simple Query for you but I was missing the logic.
I have Tab A this does have 4 records.
Tab B this does have 14 records.
Note: those 4 records exists in Tab B
I want to insert rest of the 10 records into the Tab A.
Any suggestion pls.
Thanks,
SivaHi,
Please run the below script and see if it serves your requirement.
DECLARE @TableA TABLE
ID INT,
NAME VARCHAR(10)
INSERT INTO @TableA
VALUES (1, 'James')
,(2, 'Ramz')
,(3, 'Chandu')
,(4, 'Suraj')
SELECT *
FROM @TableA
DECLARE @TableB TABLE
ID INT,
NAME VARCHAR(10)
INSERT INTO @TableB
VALUES (1, 'James')
,(2, 'Ramz')
,(3, 'Chandu')
,(4, 'Suraj')
,(5, 'Krishna')
,(6, 'John')
SELECT *
FROM @TableB
Now as per your requirement, you need to insert rows 5 & 6 from TableB into TableA
INSERT INTO @TableA
SELECT Tab1.*
FROM @TableB Tab1
LEFT JOIN @TableA Tab2 ON Tab1.id = Tab2.id
WHERE Tab2.id IS NULL
The above query gives inserts the non-existing records
SELECT *
FROM @TableA
Thanks, Satish Chandra -
Join two tables - column merge
Table1 - Product ID, Description
Table 2 - Product ID, Cost
I want the result to contain Product ID, Description and Cost. Which process should I use?
BalajiDefine a lookup against the table you want to check against. (Right-click on Reference Data node in the project browser, Add Lookup). The lookup can be to either staged data or external data (if the data is dynamic)
Then add a Lookup and Return processor to your process and configure the options. You can check for the correct cardinality if required.
If you are doing a 1:M lookup and want to create a 'join' in the process, input all the array attributes from Lookup and Return into a single Split Records from Array processor and then either Write or do other downstream processing on the joined stream. -
Combining two single recordset into one two column recordset
Hi Forum
Assume we have three types , each 'table of'
CREATE OR REPLACE type type1 as table of number ;
CREATE OR REPLACE type type2 as table of varchar2 (255);
CREATE OR REPLACE TYPE TYPEVALUE AS OBJECT
(object_type number ,
object_value varchar2(255)
resultset1 type1 := type1() ;
resultset2 type2 := type2() ;
resultset3 typevalue := typeValue3() ;
I want to populate records of resultset3 from resultset1 and resultset2 , using resultset1 for first column of record and resultset2 for second column.
One way is to do for loop but I don't want to use this.
I need something similar to resultset3 to use it dynamically in select statement to do MINUS operation with another resultset . I think things like MULTISET, COLLECT, CAST can achieve what I want to do.
Can you please help me to have a select statement that combines two single column rowset and put into a two column recordset.
ThanksHi,
You can do something like this:
SQL> create or replace type type1 as table of number;
2 /
Type created.
SQL> create or replace type type2 as table of varchar2(255);
2 /
Type created.
SQL> create or replace type typevalue as object(object_type number, object_value varchar2(255));
2 /
Type created.
SQL> create type typevalue_tab as table of typevalue;
2 /
Type created.
SQL> ed
1 declare
2 resultset1 type1 := type1(1, 2, 3, 4, 5);
3 resultset2 type2 := type2('one', 'two', 'three', 'four', 'five');
4 resultset3 typevalue_tab;
5 begin
6 for l_res in (
7 select typevalue(t1.col1, t2.col2) as col
8 from (
9 select column_value col1
10 , rownum rn
11 from table(cast(resultset1 as type1))
12 ) t1
13 , (
14 select column_value col2
15 , rownum rn
16 from table(cast(resultset2 as type2))
17 ) t2
18 where t1.rn = t2.rn
19 )
20 loop
21 dbms_output.put_line(
22 'Object Type: '||l_res.col.object_type||' '||
23 'Object Value: '||l_res.col.object_value
24 );
25 end loop;
26* end;
SQL> /
Object Type: 1 Object Value: one
Object Type: 2 Object Value: two
Object Type: 3 Object Value: three
Object Type: 4 Object Value: four
Object Type: 5 Object Value: five
PL/SQL procedure successfully completed.All the work here is done in SQL so it should work similarly if you have these things defined as nested table columns in the database.
However, there is a caveat here: the lines highlighted in bold above are defining an arbitrary ordering for the nested table elements using rownum, as there is no concept of ordering within a nested table. You should change this part of the query to whatever makes sense in your environment, otherwise this solution cannot be guaranteed to be correct. Another option would be to use VARRAYs, as they will retain the order of elements.
cheers,
Anthony
Maybe you are looking for
-
JSP is not getting displayed in add portlet repositery
Hi, I have registered two servlet in provider.xml and I was able to view that servlet as a portlet in add portlet repositery. After that I wanted to add one more JSP as portlet under same provider. So I have kept JSP in same directory where servlet i
-
How can I run the report for different input values at the same time?
Reports version: Report Builder 6.0.8.13.1 Oracle version: Oracle8i Enterprise Edition Release 8.1.7.0.0 I want to run the same report for different input parameter values and spool each o/p to different file and ftp to a server. For this, as a first
-
You-Tube Videos on Macbook Pro
Suddenly I have a problem when viewing You-Tube-Videos. They keep breaking up on my Macbook pro. I never had this problem before. My browser is Safari. Any suggestions?
-
What does the iCloud with a phone number beside it mean when I pull my screen up on safari?
when I press the + button on the bottom of screen on safari, I see a little iCloud with a phone number beside it that is not mine. what does this mean?
-
BI content cube or copy of Bi content cube is recommended
Hello all, in any implementation , we should use Standard BI content activation of cube or copy the BI content as Z and use? Please suggest. Thanks.