transpose

Transpose one row into many rows Oracle

一曲冷凌霜 提交于 2019-12-19 09:49:13
问题 I have a query that always returns one row, with many columns. I would like to turn this into 2 columns and many rows. Original results: Col1, Col2, Col3, Col4 ---------------------- val1, val2, val3, val4 What I want: ColName, Value -------------- Col1, val1 Col2, val2 Col3, val3 Col4, val4 Is this possible? EDIT (clarification) I'm looking for an automatic way of doing this. IE something I can pass results from any query that only returns 1 line. 回答1: Are you using Oracle 11g? Did you try

Transposing arbitrary collection-of-collections in Scala

独自空忆成欢 提交于 2019-12-19 06:02:44
问题 I have to often transpose a "rectangular" collection-of-collections in Scala, e.g.: a list of maps, a map of lists, a map of maps, a set of lists, a map of sets etc. Since collections can be uniformly viewed as a mapping from a specific domain to a co-domain (e.g.: a List[A]/Array[A] is a mapping from the Int domain to the A co-domain, Set[A]is a mapping from the A domain to the Boolean co-domain etc.), I'd like to write a clean, generic function to do a transpose operation (e.g.: turn a map

How to transpose MYSQL db in PHP

北战南征 提交于 2019-12-18 18:27:30
问题 I am using PHP to query a MYSQL db to output data to a csv file. I am currently able to query the db and export the data to the CSV file. However i am unable to transpose the data so that the columns are rows, and rows are columns. CODE: function transpose($array) { if (!is_array($array) || empty($array)) { return array(); else { foreach ($array as $row_key => $row) { if (is_array($row) && !empty($row)) { //check to see if there is a second dimension foreach ($row as $column_key => $element)

Move data from multiple columns into single row

谁说胖子不能爱 提交于 2019-12-18 09:36:44
问题 This formatting issue is confusing me. I'm not an Excel king and would greatly appreciate the solution to my problem. I'm trying to format data from multiple columns into a single row by date. i.e.: I've tried to search for solutions regarding transpose, but this seems a bit more involved. I have 4x data results for each date (as seen in the before column). 回答1: Here is a simple loop that works bottom up in the sheet, shifts last line over 4 columns, copies line above down and then deletes

Transposing CSV data in Perl

ぃ、小莉子 提交于 2019-12-18 09:06:26
问题 I am a Perl beginner and currently working on a Perl script to automate some of our tasks. One script that I'm working on involves extracting performance data from our system, storing it in CSV files and generating Excel graphs. After a few days of working on this script, I have managed to get the extracted data into CSV, but now, I am having hard time in trying to transpose the data! I have seen this thread (thanks to dalton for the script): stackoverflow thread, but I can't seem to apply it

Transpose a row into columns with MySQL without using UNIONS?

被刻印的时光 ゝ 提交于 2019-12-18 07:15:06
问题 I have a table that is similar to the following below: id | cat | one_above | top_level | 0 'printers' 'hardware' 'computers' I want to be able to write a query, without using unions , that will return me a result set that transposes this table's columns into rows. What this means, is that I want the result to be: id | cat | 0 'printers' 0 'hardware' 0 'computers' Is this possible in MySQL? I can not drop down to the application layer and perform this because I'm feeding these into a search

How can I transpose different sized ruby arrays?

ぃ、小莉子 提交于 2019-12-18 04:48:12
问题 I have an array: arr=[[1,2,3],[4,5],[6]], I have the following code: arr.transpose but it doesn't work,how to solve it? I am getting [[1,2,3],[4,5],[6]].transpose IndexError: element size differs (2 should be 3) from (irb):13:in `transpose' from (irb):13 from /home/durrant my solution: arr.reduce(&:zip).map(&:flatten) output: [[1, 4, 6], [2, 5, nil], [3, nil, nil]] 回答1: A similar answer was posted (but deleted) an hour earlier: arr = [[1, 2, 3], [4, 5], [6]] arr[0].zip(*arr[1..-1]) #=> [[1, 4

How do I transpose a List? [duplicate]

為{幸葍}努か 提交于 2019-12-17 20:54:56
问题 This question already has answers here : Transpose list of lists (10 answers) Closed 5 years ago . Let's say I have a SINGLE list [[1,2,3],[4,5,6]] How do I transpose them so they will be: [[1, 4], [2, 5], [3, 6]] ? Do I have to use the zip function? Is the zip function the easiest way? def m_transpose(m): trans = zip(m) return trans 回答1: Using zip and *splat is the easiest way in pure Python. >>> list_ = [[1,2,3],[4,5,6]] >>> zip(*list_) [(1, 4), (2, 5), (3, 6)] Note that you get tuples

Transpose Excel column to rows

跟風遠走 提交于 2019-12-17 20:16:17
问题 I have an Excel sheet that looks like the first picture and I want to convert it to the second picture: I have written the following code but it does not work as expected. It deletes more rows than expected. What's wrong with the code? Sub Trans3() Dim rng As Range, rng2 As Range Dim I As Long Dim J As Integer, Z As Integer, Q As Integer, T As Integer Set rng = Range("B1") While rng.Value <> "" For Each y In Range("A1:A10") I = I + 1 J = I Z = 1 Do While Cells(J + 1, 1).Value = Cells(J, 1)

Transpose mysql query rows into columns

我的未来我决定 提交于 2019-12-17 19:53:10
问题 I have a simple query that produces the below results: SELECT month,transporttype,count(transporttype) as loads from deliveries group by month,transporttype I would like to transpose the rows into columns. I understand mysql does not have pivot functions so a union is required but not 100% sure. Thanks in advance for the help. 回答1: You can do it with a crosstab like this - SELECT `year`, `month`, SUM(IF(`transporttype` = 'inbound', 1, 0)) AS `inbound`, SUM(IF(`transporttype` = 'LocalPMB', 1,