Please help to generate the table from column to rows
Hello -
I have one table with more than 100 columns there are 70 column start with HC1.....HC70 (they are not in sequence) and has some value 0 or 1
Table structure:
HICN_ID HC1 HC2 HC4 HC5 HC6.................................HC70
1234A 0 1 1 0 1 1
3456D 1 0 0 1 0 0
Now What i want is like this..
HICN_ID HC
1234A 2
1234A 4
1234A 6
3456D 1
3456D 5
Can you please help me on this
thanks
nick
Please look at the same scenario from the below link.
You can accomplish this by a "pivot" query. Please look at the small testcase that I prepared below:
SQL> desc t1
Name Null? Type
NAME VARCHAR2(10)
YEAR NUMBER(4)
VALUE NUMBER(4)
SQL>
SQL> select * from t1;
NAME YEAR VALUE
john 1991 1000
john 1992 2000
john 1993 3000
jack 1991 1500
jack 1992 1200
jack 1993 1340
mary 1991 1250
mary 1992 2323
mary 1993 8700
9 rows selected.
SQL> -- now, try out the pivot query
SQL> select year,
2 max( decode( name, 'john', value, null ) ) "JOHN",
3 max( decode( name, 'jack', value, null ) ) "JACK",
4 max( decode( name, 'mary', value, null ) ) "MARY"
5 from
6 (
7 select name, year, value
8 from t1
9 )
10 group by year ;
YEAR JOHN JACK MARY
1991 1000 1500 1250
1992 2000 1200 2323
1993 3000 1340 8700
SQL>
Hope that helps.
Source : http://p2p.wrox.com/oracle/11931-sql-query-convert-columns-into-rows.html
Thanks,
Balaji K.
Similar Messages
-
HT3702 please help to solve the violation from itunes
please help to solve the violation from itunes
Sorry, but the minimal amount of information you have provided does not allow us to understand what problem you are having. You will need to post a more complete description of your issue before anyone can even guess at suggestions.
Regards. -
Urgent please help: what is the table name for cash management reports?
I am wondering what the table name for cash management reports is. I am trying to figure out then if I have any missing.
Please help.I checked MSEG table. But, I didn't find any field for date.
Can you tell me field name.
Regards
Siva -
Please help me update the vi from 5.1 to 8.6
please help me update the vi and its sub vi from 5.1 to 8.6 . thanks very much
Attachments:
NI-DSA Swept Sine Audio Tester13.llb 498 KBattached
Attachments:
NI-DSA Swept Sine Audio Tester13.llb 131 KB -
Please help me- hide the table in xml template
Display the PDF output sum table not a return any data, I want to hide that table's
Edited by: 991575 on Mar 4, 2013 1:12 AM
Edited by: VEERUAPPS on Mar 31, 2013 10:05 PMHi ,
1.If bi is integrated with bo then you create YTD variable using customer exit as processing type in BEX report and use this variable in WEBI Report.
2.You create one variable for start of the year by using concatenation function("1/1/2010") and create on variable for current date and use the between function in the prompt in the webi reports.
Hope it will give some idea.
Regards,
Ramnaresh.P. -
Need help in generating the ranks
Hi,
I need some help in generating the ranks from 1 to 6 for each order_id
based on the item_cnt
Order_Id 100 with the Item_cnt 217,112,89,76,55,39 to be ranked from 1 to 6
Order_Id 200 with the Item_cnt 29,25,22,19,13,13 to be ranked from 1 to 6
Order_id 300 with the Item_cnt 15,7,6,6,6,4 to be ranked from 1 to 6
SOURCE DATA TABLE : ORD_TEST
ORDER_ID ORDER_IN_DATE ORDER_OUT_DATE ITEM_CNT
100 9/11/2012 9/12/2012 217
100 9/13/2012 9/15/2012 112
100 9/14/2012 9/17/2012 89
100 9/13/2012 9/16/2012 76
100 9/12/2012 9/15/2012 55
100 11/9/2012 11/18/2012 39
100 9/14/2012 9/18/2012 37
100 9/20/2012 9/22/2012 32
200 11/9/2012 11/18/2012 29
200 9/13/2012 9/15/2012 25
200 9/12/2012 9/15/2012 22
100 9/12/2012 9/14/2012 22
100 9/13/2012 9/17/2012 20
200 9/14/2012 9/17/2012 19
100 9/14/2012 9/16/2012 19
100 9/13/2012 9/18/2012 18
100 9/12/2012 9/19/2012 15
300 9/11/2012 9/12/2012 15
200 9/12/2012 9/16/2012 13
200 9/22/2012 9/29/2012 13
200 9/13/2012 9/17/2012 12
200 10/5/2012 10/8/2012 9
300 9/12/2012 9/18/2012 7
300 9/12/2012 9/17/2012 6
300 10/6/2012 10/10/2012 6
300 4/25/2013 4/27/2013 6
300 10/6/2012 10/9/2012 4
300 9/16/2012 9/23/2012 2
100 10/5/2012 10/8/2012 1
200 9/11/2012 9/12/2012 1
QUERY OUTPUT NEEDED IS
ORDER_ID ORDER_IN_DATE ORDER_OUT_DATE ITEM_CNT RNK
100 9/11/2012 9/12/2012 217 1
100 9/13/2012 9/15/2012 112 2
100 9/14/2012 9/17/2012 89 3
100 9/13/2012 9/16/2012 76 4
100 9/12/2012 9/15/2012 55 5
100 11/9/2012 11/18/2012 39 6
200 11/9/2012 11/18/2012 29 1
200 9/13/2012 9/15/2012 25 2
200 9/12/2012 9/15/2012 22 3
200 9/14/2012 9/17/2012 19 4
300 9/11/2012 9/12/2012 15 1
200 9/12/2012 9/16/2012 13 5
200 9/22/2012 9/29/2012 13 6
300 9/12/2012 9/18/2012 7 2
300 9/12/2012 9/17/2012 6 3
300 10/6/2012 10/10/2012 6 4
300 4/25/2013 4/27/2013 6 5
300 10/6/2012 10/9/2012 4 6
Below is the script
CREATE TABLE ORD_TEST (ORDER_ID NUMBER, ORDER_IN_DATE
DATE,ORDER_OUT_DATE DATE, ITEM_CNT NUMBER)
INSERT INTO ord_test VALUES
(100,TO_DATE('9/11/2012','MM/DD/YYYY'),TO_DATE('9/12/2012','MM/DD/YYYY'),217);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),112);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),89);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/16/2012','MM/DD/YYYY'),76);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),55);
INSERT INTO ord_test VALUES
(100,TO_DATE('11/9/2012','MM/DD/YYYY'),TO_DATE('11/18/2012','MM/DD/YYYY'),39);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/18/2012','MM/DD/YYYY'),37);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/20/2012','MM/DD/YYYY'),TO_DATE('9/22/2012','MM/DD/YYYY'),32);
INSERT INTO ord_test VALUES
(200,TO_DATE('11/9/2012','MM/DD/YYYY'),TO_DATE('11/18/2012','MM/DD/YYYY'),29);
INSERT INTO ord_test VALUES
(200,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),25);
INSERT INTO ord_test VALUES
(200,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),22);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/14/2012','MM/DD/YYYY'),22);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),20);
INSERT INTO ord_test VALUES
(200,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),19);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/16/2012','MM/DD/YYYY'),19);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/18/2012','MM/DD/YYYY'),18);
INSERT INTO ord_test VALUES
(100,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/19/2012','MM/DD/YYYY'),15);
INSERT INTO ord_test VALUES
(300,TO_DATE('9/11/2012','MM/DD/YYYY'),TO_DATE('9/12/2012','MM/DD/YYYY'),15);
INSERT INTO ord_test VALUES
(200,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/16/2012','MM/DD/YYYY'),13);
INSERT INTO ord_test VALUES
(200,TO_DATE('9/22/2012','MM/DD/YYYY'),TO_DATE('9/29/2012','MM/DD/YYYY'),13);
INSERT INTO ord_test VALUES
(200,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),12);
INSERT INTO ord_test VALUES
(200,TO_DATE('10/5/2012','MM/DD/YYYY'),TO_DATE('10/8/2012','MM/DD/YYYY'),9);
INSERT INTO ord_test VALUES
(300,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/18/2012','MM/DD/YYYY'),7);
INSERT INTO ord_test VALUES
(300,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),6);
INSERT INTO ord_test VALUES
(300,TO_DATE('10/6/2012','MM/DD/YYYY'),TO_DATE('10/10/2012','MM/DD/YYYY'),6);
INSERT INTO ord_test VALUES
(300,TO_DATE('4/25/2013','MM/DD/YYYY'),TO_DATE('4/27/2013','MM/DD/YYYY'),6);
INSERT INTO ord_test VALUES
(300,TO_DATE('10/6/2012','MM/DD/YYYY'),TO_DATE('10/9/2012','MM/DD/YYYY'),4);
INSERT INTO ord_test VALUES
(300,TO_DATE('9/16/2012','MM/DD/YYYY'),TO_DATE('9/23/2012','MM/DD/YYYY'),2);
INSERT INTO ord_test VALUES
(100,TO_DATE('10/5/2012','MM/DD/YYYY'),TO_DATE('10/8/2012','MM/DD/YYYY'),1);
INSERT INTO ord_test VALUES
(200,TO_DATE('9/11/2012','MM/DD/YYYY'),TO_DATE('9/12/2012','MM/DD/YYYY'),1);
select * from ord_test order by item_cnt desc;
Thank youHi,
That's called a Top-N Query , and here's one way to do it:
WITH got_rnk AS
SELECT o.*
, ROW_NUMBER () OVER ( PARTITION BY order_id
ORDER BY item_cnt DESC
) AS rnk
FROM ord_test o
SELECT *
FROM got_rnk
WHERE rnk <= 6
ORDER BY order_id
, rnk
;Analytic functions (such as ROW_NUMBER) are computed after the WHERE clause is applied. If you want tio use the results of an analytic function in a WHERE clause, then you can compute the analytic function in a sub-query (such as got_rnk above), and then use that value in the WHERE clause of a super-query. -
Alter table type from COLUMN to ROW
TABLE type can be changed from ROW to COLUMN (and vice versa) using the ALTER TABLE command .
Lars Breddemann wrote
when considering which data store to choose (which, by the way, can be changed later on as well), you have to take into account:
* will you usually need the complete row (all columns)? If so, row store may be more efficient, as reconstructing the complete row is one of the most expensive column store operations.
* will you need to join the row-store table to a column store table? If so, you should avoid using a different storage type, since using both storage engines in a statement leads to intermediate result set materialization which is another name for bad performance.
* do you want to fill the table with huge amounts of data, that should be aggregated and analysed? If this is the case, the column store is the better option.
As a rule of thumb you may just start with column-store tables and change them to row-store tables when you encounter performance issues.
In general most developers cannot anticipate all important use cases for the tables they design.
This is especially true for living and growing systems.
So, more important than choosing the 'right' storage in the beginning is to monitor the performance and to benchmark the differences when changing the storage engine.
So suppose we have a COLUMN table , but would be requiring to get data from many columns (so would be a very expensive column operation) , would it be advisable to change the table type FROM COLUMN to ROW on the fly . would this be a resource intensive operation if the table has a lot of data ?
Lets suppose , if the above can be done , but there exists a interdependency for the column table (say from another simultaneous operation) , and thus should remain as COLUMN table as such . so what would be the better option in this case .
Creating views is not an option as it seems from the SQL guide , that there was not an option to create a ROW view from a COLUMN table. ?
Edited by: Rajarshi Muhuri on Nov 27, 2011 3:25 AMDear Rajashri,
1. you cann't alter table from column to row using alter command.
but you can achieve this through Stored procedure, just Little bit HSQL coding.
I hope upcoming versions SAP Gives like following SQL statements ( following statemnt not works in HANA works in oralce )
create row table "EFASHION_TUTORIAL"."AAA" as
select
"ARTICLE_COLOR_LOOKUP_ID",
"ARTICLE_ID",
"COLOR_CODE",
"ARTICLE_LABEL",
"COLOR_LABEL",
"CATEGORY",
"SALE_PRICE",
"FAMILY_NAME",
"FAMILY_CODE"
from "EFASHION_TUTORIAL"."ARTICLE_COLOR_LOOKUP";
2. Row & column table two different purpose like OLTP & OLAP.
when you think about OLAP means modeling use Column.
when you think about OLTP means real time operations then use Row
Column table is high compress ( 5 - 20X), i don't think you want get any performance issue when read information from column table. that is actual Core engine reading parller process. ( that is Heart of HANA).
Column table purpose quite different like calculations, grouping.. most of DW environment Queires.
Row table is currently system tables in feature row tables as OLTP, it's less compress mode compress to column store.
so finally you write small program convert column to row and row to column
thanks
Rao -
Can we hide the tables and columns from subject areas in the front end
Hi,
Is there any way to hide the tables and columns from the subject area in front end.I need to create a report with some tables which the user does not want to see.So after creating the reprot can I hide those tables and columns in the front endHi,
Your question is not that clear to me...do you want to hide the entire table/column that dont want to show up in the front end then you could do in Presneation Layer in the RPD by going Permissions in the property of that object.
But if you want to hide the column in the report that can be visible in the subject Area: go to column properties -> Column fomat...thereis Hide option.
Can you please elaborate your question...what exactly you are looking for...
--SK -
The enter key is not working in firefox but it has working fine in chrome and IE so please help me to rid out from this.
Hello gokulaan, '''try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
''(If you're not using it, switch to the Default theme.)''
* You can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
* Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
''Once you get the pop-up, just select "'Start in Safe Mode"''
'''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
''When you figure out what's causing your issues, please let us know. It might help other users who have the same problem.''
Thank you. -
How to transfer the tables from one file group to another file group in SQL 2008.?
Hello all,
I have few issues regarding the transfer of the tables from one file group to another file group in SQL 2008 and also How can we backup
and restore the particular database based on file group level.
Let’s say I have a tables stored within the different FG. such as
Tables
File group
Dimension tables
Primary
Fact tables
FG1
FG2…
zzz_tables
DEFAULT_FG
dim.table1 DEFAULT_FG
dim.table2 DEFAULT_FG
Here all I want to transfer the dim.table1 ,dim.table2 from DEFAULT_FG to the Primary File
group .So is there simple methods for transfer the dim.table1,2 from one FG to another .I have tried somewhat but I couldn’t get the exact way .So if someone have better idea please share your knowledge that would be really appreciated.
Secondly after moving those dim.table1 ,dim.table2 from DEFAULT_FG to Primary ,All I want to backup and restore the database only containing the Primary and FG1,FG2… not
a DEFAULT_FG.Is it possible or not.?
Hope to hear from the one who knows better approach for this kind of task .Your simple help will be much appreciated.
Regards,
Anil MaharjanWell after all my full day research on this topic had paid off, I finally got the solution and am so happy to research on these things. It makes
us feel really happy after all our research and hard work doesn't goes as waste.
Finally I got what I am looking for and want to make sure that I am able to transfer the tables from DEFAULT_FG to another FG without tables
having clustered index on that tables .
With the help of the link below I finally got my solution where Roberto’s coded store procedure simply works for this.
Really thanks to him for his great post and thanks to all for your response and your valuable time.
http://gallery.technet.microsoft.com/scriptcenter/c1da9334-2885-468c-a374-775da60f256f
Regards,
Anil Maharjan -
Insert Multiple rows into the table from that table data
Hi All,
I have a requirement like to insert mulitple rows into the table from that table data only(I need to replicate the data).
In this table primary key is composite primary key with all foreign keys.primary key also including the Date foreign key.I need to change that date at the of insertion.
INSERT
INTO myschema.Fact_page_performance
time_sk ,
batch_id ,
delta_msec ,
delta_user_msec,
error_code_sk ,
content_errs ,
element_count ,
page_bytes ,
Available ,
date_sk
VALUES
(SELECT time_sk ,
batch_id ,
delta_msec ,
delta_user_msec,
error_code_sk ,
content_errs ,
element_count ,
page_bytes ,
Available
FROM myschema.FACT_PAGE_PERFORMANCE_BACKUP
WHERE date_sk=20090509,20090510
But it is giving the error like missing Expression.
Could anyone please help to me.
Thanks and Regards
Swetha.You can have either VALUES or SELECT not both
INSERT
INTO myschema.Fact_page_performance
time_sk ,
batch_id ,
delta_msec ,
delta_user_msec,
error_code_sk ,
content_errs ,
element_count ,
page_bytes ,
Available ,
date_sk
SELECT time_sk ,
batch_id ,
delta_msec ,
delta_user_msec,
error_code_sk ,
content_errs ,
element_count ,
page_bytes ,
Available
FROM myschema.FACT_PAGE_PERFORMANCE_BACKUP
WHERE date_sk=20090509,20090510; -
How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?
I tried using DROP Tables, Truncate Database, Delete and many more but it is not working. I want to delete all tables using Query Analyzer, i.e. through SQL Query.
Please help me out in this concern.
Nishith ShahInformative thread indeed. Wish I saw it early enough. Managed to come up with the code below before I saw this thread.
declare @TTName Table
(TableSchemaTableName
varchar
(500),
[status] int
default 0);
with AvailableTables
(TableSchemaTableName)
as
(select
QUOTENAME(TABLE_SCHEMA)
+
+
QUOTENAME(TABLE_NAME)
from
INFORMATION_SCHEMA.TABLES)
insert into @TTName
(TableSchemaTableName)
select *
from AvailableTables
declare @TableSchemaTableName varchar
(500)
declare @sqlstatement nvarchar
(1000)
while 1=1
begin
set @sqlstatement
=
'DROP TABLE '
+ @TableSchemaTableName
exec
sp_executeSQL
@sqlstatement
print
'Dropped Table : '
+ @TableSchemaTableName
update @TTName
set [status]
= 1
where TableSchemaTableName
= @TableSchemaTableName
if
(select
count([Status])
from @TTName
where [Status]
= 0)
= 0
break
end -
Generate delete tables from dictionary
Hi,
I have a CAF project that I´ve imported from a track, so far ok, I click to build and it works, but when I try generate it again it marks the tables from the dictionary project as deleted and remove them from my project, so i have two doubts:
1 - Has any one any idea what happened? Why they are deleted?
2 - Is it possible to undelete the table? The file still there but all the configuration is lost, the list of columns is lost.
Thanks and best regards,
EduardoIn the package hierarchy (applications navigator), right-click the package containing your EO's, choose "Generate Database Objects"
Voila
John -
Hi there. Can someone please help me with copying photos from my old iPad to my new ipad2? Thanks.
If you have a pc, when you plug your iPad in you should see the windows pop up window offering to backup the photos. Do that and it will save all your photos and videos to your computer where you can then sync them back to your new one.
If the pop up doesn't come up, double click on my computer and navigate your way to the iPad. Double cick on it an d navigate to the DCIM folder. Drag your photos and videos to your pc, then sync them back onto your iPad. -
Please help me with the digital signature validation problem?
Please help me with the digital signature validation problem?
Hi
Execute the program in the Debuggin mode.
In the Debugger Window
Select Breakpoint -> Break point at -> Breakpoint at source code Menu Item and enter the details of the program/include/line no..
Activate the System Debugger On from the Settings Menu.
Hope this would help you.
Murthy
Edited by: Kalyanam Seetha Rama Murthy on Jul 18, 2008 7:20 AM
Maybe you are looking for
-
I have tried to open Firefox, but it just sits there and doesn't load. I have tried to uninstall and reinstall but that works for a few hours and then it goes back to not loading. I don't know what else to do to get it too load.
-
Document date for PO..?
Hi all I was using IDES, here i have done configuration . while creating the PO , the document date in PO is showing 1 year before ,,i.e for example today if i create a po document in po is 1.10.2007.. Please guide me were to do the setting for docum
-
Why does the 'Downloads' gives me a full page which I can not just minimize to the task bar.
I'm running Firefox 34.05 as opposed to what the data will say (34.0) Lately, when I press the 'Downloads' in Tools, I get a full page as if it is a new tab. I use to have a small block that I could minimize to the task bar. Is there something I can
-
Error, missing customer master when creating sales order, master data exist
Hi, i am trying to create a sales order but the systems gives me an error that the customer does not exist, whereas the customer record does exist and was created centrally. please help me resolve this issue. Thanks Admire
-
Call labview vi interactiv​ely from diadem 10
Hi, I am trying to run a LabVIEW VI from DIAdem. I have LabVIEW 7.1 loaded on my machine and got Diadem 10. I have downloaded the tool for calling LabVIEW VIs interactively from DIAdem but am unable to run my VI. Only VIs from library DIAdem_selectV