Add multiple column values in another column
Hello
I have a table with structure below
Date of the transaction | Country | Division of | Entity | Flag | Total |
---|---|---|---|---|---|
January 5, 2015 | GB | 11 | CR | News errors | 5 |
January 5, 2015 | GB | 11 | Pass | News errors | 5 |
I need to display it in below format
Date of the transaction | Country | Division of | CR-news mistakes | Spend-news mistakes | Total-news mistakes |
---|---|---|---|---|---|
January 5, 2015 | GB | 11 | 5 | 5 | 10 |
If you see the above format, I want the lines had to be transposed to the columns that depends on the value of the INDICATOR. A flag as 'New errors' entry will have a multiple entity (Cr, spend)
On this basis, we must for the Date of the Transaction, country, Division of the Group and display the data.
Sum of the total errors in a specific indicator should be displayed in a column.
I tried under query to convert the columns.
Select t.transaction_dt, t.cntry_id, t.div_id,
NVL ()max()decode(t.entity | ) '-' : t.Flag, ' CR-news mistakes ' , t.TOTAL)),0) 'CR-news mistakes',
NVL ()max()decode(t.entity | ) '-' | t.Flag,'Spend -new errors , t.TOTAL)),0) 'Autori-news mistakes'
table t
Group of t.transaction_dt, t.cntry_id, t.div_id;
In the above how to get the sum total columns for this type of query hint.
Help, please.
Something like this maybe?
SELECT transaction_dt,
cntry_id,
div_id,
Sum(case when Entity = 'CR' and Flag = 'New Errors' Then total else 0 end) CR_New_Errors,
Sum(case when Entity = 'Spend' and Flag = 'New Errors' Then total else 0 end) Spend_New_Errors,
Sum(case when Flag = 'New Errors' Then total else 0 end) Total_New errors
-... etc for all other combinations of flag and entity...
From your_table
Transaction_dt GROUP, cntry_id, div_id
Tags: Database
Similar Questions
-
How to make a multiple numeric value to another page
Dear Experts,
Apex 4.1
Oracle 11g
I would like to pass multiple numeric value to another page, as below:
P1_ID = (11,22,33) POINT Page1 depend on what users chose
P2 SQL: SELECT * FROM TABLE WHERE ID IN (11,22,33), ID is numeric fields.
but the PAGE 2 to show the error invalid number, how to fix, please help me.
Thanks and greetings
Yong Huang wrote:
Dear Experts,
Apex 4.1
Oracle 11g
I would like to pass multiple numeric value to another page, as below:
P1_ID = (11,22,33) POINT Page1 depend on what users chose
P2 SQL: SELECT * FROM TABLE WHERE ID IN (11,22,33), ID is numeric fields.
but the PAGE 2 to show the error invalid number, how to fix, please help me.
This is the classic problem 'variable IN the list' (I have no idea why this misunderstanding is so widespread. Always seemed obvious to me that it doesn't). In
select * from table where columnvalue in (7788, 7839, 7876)
(7788, 7839, 7876)
is a list of expressions and the predicate is evaluated as a membership condition.In
select * from table where columnvalue in :P1_X
:P1_X
is a scalar string, unable to contain multiple values.In a report of type APEX, a source report of the body of the PL/SQL function returning a SQL query with lexical substitution can be used to produce a "variable list:
return 'select * from table where columnvalue in (' || :P1_X || ')';
where
P1_X
contains less than 1000 values, has been disinfected to code SQL injectionand string values are properly cited.Some people suggest the following approach, that will work also in interactive APEX reports:
select * from table where instr(':' || :P1_X || ':', ':' || columnvalue || ':') > 0
However, it is underperforming because it eliminates the possibility of using the index optimizer or the size of the partition in the execution plan.
See various elements in the list to ask Tom and imitating the channel to the table using sql features for effective solutions.
-
How to add multiple fields values
I think it's simple, but I don't see how. I have 5 or 6 entered by the user different market values that I need to calculate a total for.
Example of
1 cleaning $10.00 fee
2 deposit $10.00
3 company $10.00 deposit
4 total amount of the rent $70.00
5 total $100.00
If a user would enter values for 1-4 and it calculates the total in zone 5. If we assume that $0.00, it would be great if a user left an empty field. I'm leaving the script somehow, but looking for a little guidance? Thank you all...
Greetings,
Place it inside the event, calculate the total by using FormCal field option
yourfieldname + yourfieldname + yourfieldname + yourfieldname
Here is a link to a form that contains an example of adding:
http://www.shingleme.com/AdditionTest.PDF
Justin
-
Add more columns in number 3.6.1
I need to add many columns in the middle of a worksheet. I know a couple of ways of adding them one at a time, but does anyone know a way to add multiple columns at the same time?
Hi terydeb,
An example of insertion of two columns. Select the cells on two columns
Hold down the option key and press the right arrow on the keyboard
Kind regards
Ian.
-
Add column if the value in another column
How can I add a column as column name 'YES_OR_NO.
SELECT VALUE_ID IN THE TABLE TABLE_NAME
VALUE_ID
---
1
2
3
4
5
Now, I want to create another column in the sql query called YES_OR_NO and that if there is a value in VALUE_ID then column YES_OR_NO must say 'YES' if there is no value in the column VALUE_ID of this line YES_OR_NO must say 'NO '.
or just a way for her also to work would be to show this new column or not if a value in another column of table_name_2 (this would be ideal)
If new column yes_or_no and fill by a Yes or a no if a value is found in another tableAssuming that you are on a version that supports the CASE expression:
SELECT VALUE_ID , case when VALUE_ID is null then 'NO' else 'YES' end as YES_NO FROM TABLE_NAME
-
Column sum based on a single value of another column
Hi all
I've searched and searched, but just can't find if this is even possible, let alone how to do it. What I'm trying to do, it's the sum of a column. However, only summarize the results of this column if a specific value of another column is present. So, for example, the following is a sample database entry:
Rate of pay hours
2.3 $14.00
1.2 $14.00
2.4 $12.50
0.75 $12.50
So for that, I want the sum of hours worked column but only the sum of hours worked if the wage rate is $14.00 and $ 12.50. Because these numbers are generated in a database (with the various people who enter multiple rates of pay), I won't be able to set the where statement to have a specific amount (since I don't know the specific amount each registrant), the amount must be a variable in the where the statement. With MySQLI, I know not how to make the sum of hours worked, but I do not know how the sum of hours worked if and only if the line corresponds to the unique value in the rate column.
Then have it automatically loop through and total hours worked for other unique values in the column salary rate. Finally, out all unique values in the column rate in variables so that I can do the following for each game:
$total1 = $total_hours1 * $wage_rate1 $total2 = $total_hours2 * $wage_rate2 $overall_total = $total1 + $total2
where $wage_rate1 = $14.00 and $total_hours1 = 2.3 + 1.2: etc.
Is it still possible? If so, how? If possible, can someone please let me know a good reference so I can learn how to be the best way to implement?
Thank you
So with that, I get the correct $final_total printed, but I still get the error, 'notice: Undefined variable: final_total. Why is it not defined, but prints the total exact? How to remove the error?
You get this notice is because you use the assignment combined, operator that is normally used to add a value to a variable and assign the new value to it.
$final_total += $total;
is a shortcut for this:
$final_total = $final_total + $total;
The undefined $final_total is on the right side of the assignment operator. The first time through the loop, you add $total to a non-existent value. Because of the type of PHP juggling, this becomes:
$final_total = 0 + $total;
The next time the loop runs, $final_total has a value, so that you get the view variable not defined only once.
To avoid advice, initialize $final_total to zero before the start of the loop.
$final_total = 0;
While ($row = {$sql-> fetch_array())}
-
I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?
Add two new columns after than the original with space separated values column.
Select cell B1 and type (or copy and paste it here) the formula:
= IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
shortcut for this is:
B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")
or
the formula of the C1 could also be:
= IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")
Select cells B1 and C1, copy
Select cells B1 at the end of the C column, paste
-
Gears - error when you try to insert values into a table with multiple columns
Hello
I started playing with the gears and SQlLite today and I get an error when I try to insert values into a table with multiple columns.
I have:
var db = google.gears.factory.create('beta.database'); db.open('developerSet'); db.execute('create table if not exists Developers (DeveloperName text, DeveloperAge int)'); var devName = "Davy" var devAge = 32; try { db.execute('insert into Developers values (?, ?)', [devName, devAge]); alert('success'); } catch (e) { alert(e); }
I get the error:
net.rim.device.api.database.DatabaseException; insert into developers values (?,?): SQL logic error or missing database.
I use this reference: http://code.google.com/apis/gears/api_database.html
Everything works if I have only one field as:
var db = google.gears.factory.create('beta.database'); db.open('developerSet'); db.execute('create table if not exists Developers (DeveloperName text)'); var devName = "Davy" var devAge = 32; try { db.execute('insert into Developers values (?)', [devName]); alert('success'); } catch (e) { alert(e); }
I use the plug-in Visual Studio 2.0 for 2008 that are running Windows XP SP and Simulator 2.13.0.56
Thank you
Davy
Yes, a SQLite database will persist between battery pulls. The database is registered either to internal MEM or removable media (not the device memory), depending on which is available on your device.
In general, its not considered a best practice to remove your table as soon as it is empty and re - create it again when you want to add data. This adds extra overhead fresh for the final, delete and insert first for a given table. Instead, define and finalize your drawing before you create your table. Once created, review the static schema.
That being said, for development purposes, it may be easier to provide an easy way to drop your tables while you develop your schema.
See you soon,.
Adam
-
Call a select stmt with multiple columns inside another column
Hi all
I have a question about the appeal of a select statement, which is to have multiple columns inside another select statement.
I know that we can use inline views to retrieve data from another table within a query as shown below.
SELECT (SELECT dname FROM dept WHERE deptno = e.deptno), deptno, sal FROM emp e;
Now, I'm going to pull the loc also column within the same view of inline. But oracle is not allowing me to do the same thing.
Is there a way we can achieve the same thing because I don't want to hit the area two times table each time for each emp record.
Appreciate your valuable suggestions.
Thank you
Madhu K.Maybe just a simple outer join?
select ut.subscriberid ,ut.unitid ,ut.install_date ,nvl(tuh.hardwaretype, 'NO_HW') from tt_unit ut left join tt_unit_hwtype tuh on tuh.unitid = ut.unitid where trunc(ut.install_date) >= V_CONST_PROG_START_DT;
-
Add up the values from two numeric columns on RTF model
Hello
I'm trying to add up the values of the numeric column 2.
I tried..? column_1 and column_2? > but it's not as simple as that obviously I get an error when you try to do
I tried..? sum (current - group () / column_1) + sum (current - group () / column_2)? >, but who does no more work that it also returns an error
Any ideas how to add two numeric columns in RTF model?for 2 + 3
-
How do rotate on a date and see the sum of the value of another column
Hello
I searched through the forum and cannot find a query similar to my question feels so post this new thread.
First of all, it is probably useful indicating that I am using Oracle 10 g.
I have a table that is used to store the details of the booking (essentially a booking system) and I would use this data to display the details of the customers stay on one line.
The table has the following columns:
Some example records could be:BOOKING_ID CUSTOMER_ID DATE_OF_ARRIVAL NUMBER_OF_NIGHTS NUMBER_OF_PEOPLE
On this basis I would like to display the output so that I can show a sum of the NUMBER_OF_PEOPLE reserved to per customer per day, as such:BOOKING_ID CUSTOMER_ID DATE_OF_ARRIVAL NUMBER_OF_NIGHTS NUMBER_OF_PEOPLE -------------------------------------------------------------------------------------------- 1 201 13-JAN-2010 5 1 2 202 13-JAN-2010 3 2 3 202 13-JAN-2010 4 1 4 203 15-JAN-2010 2 3
I watched analytical functions in the documentation and several books of Oracle that I have, but have so far struggled to find how to make the performance desired. Even using the excellent response to the previous post on the forum, I got I was not able to get a feasible request.CUSTOMER_ID 13-JAN 14-JAN 15-JAN 16-JAN 17-JAN 18-JAN 19-JAN ----------------------------------------------------------------------------------------- 201 1 1 1 1 1 0 0 202 3 3 3 1 0 0 0 203 0 0 3 3 0 0 0
Any help or advice would be much appreciated.
Kind regards
Stu
Published by: macmanxie on January 10, 2011 21:16Hello
macmanxie wrote:
... The suggested approach goes only to return a number if the DATE_OF_ARRIVAL corresponds to the date in the CASE statement, however I have the added complexity of wanting to show a count of all the days that the customer is booked, for, by making use of the NUMBER_OF_NIGHTS. I tried to use some of the examples provided on morganslibrary.org, for example:sum( CASE WHEN TRUNC (arrival_date) between '01/13/2011' and TRUNC (arrival_date+no_of_nights) THEN nvl(no_of_people,0) ELSE 0 END) AS jan_13
but this does not produce the desired result.
You check if arrival_date is between January 13 and arrival_date + no_of_nights (as if the arrival date could all be posterior to the arrival_date + no_of_nights).
Are not really interested in whether or not January 13 ib between arrival_date and arrival_date + no_of_nights?NVL ( SUM ( CASE WHEN TO_DATE ( '01/13/2011' , 'MM/DD/YYYY' ) BETWEEN TRUNC (arrival_date) AND TRUNC (arrival_date) + no_of_nights THEN no_of_people END ) , 0 ) AS jan_13
Always format your code. It is important to format your code if you are the only who who will ever read but it is even more important if you are posting on a forum like this and ask other people to read.
Not to compare the DATEs in the strings; explicitly use a conversion function, like TO_DATE, above, where necessary.
Both
SUM (NVL (x, 0)) and
NVL (SUM (x), 0) get the same results, but the latter is more effective. If you have 1000 lines, the first way is calling NVL 1000 times, but the second way is calling only once.If your previous thread
Re: How to count the occurrence of a date in a range
Gets you the right data, but it has one row for each distinct combination of customer_id and date, then you can switch it to a form that contains a line by the customer and another column for each date.If you need help, post CREATE TABLE and INSERT statements for some examples of data and outcomes from these data. The post you are trying better to a request, including a subquery that gets no cross-the raw table dynamic results.
There will be a fixed number of columns in the output swing? If this is not the case, how do you deal with that? Which of these options in the thread I posted above)
Re: County report and the sum of the number of rows by multiple columns
) is best for your needs? Than others is acceptable? -
Need to add a column with a default value
I need to add a column of type char (1) to a table and there should be a value default of'm '
I want to check first if this column already exists in this table.
If so, I still want to check if the default is am'
How can I do this?
I was able to all_tab_columns to query for the presence of column with the type of data and all, but not able to do the second part.
Thanks in advance.The DATA_DEFAULT field in dba_tab_columns stores information.
-
adding data lines and multiple columns with a form
I need to add multiple data rows and columns to a database using a form online and don't know what would be the best method of data entry and of insertion.
The data should look like this:
COLUMN1 COLUMN2
var1, var1
var2 var2
var3 var3
etc...
When you create the form do I create individual text fields for each var or would it be better to have a text field where they list the data. I don't know where to start.
Any advice would be great.You can use line numbers in your domain names to associate the columns for a particular record. For example, suppose you want 5 rows enter the last names and first names:
First name:
First name:
This will give you a series of areas such as lname1, lname2, fname2, $fname1, etc.
In your form, you can also include a hidden field to indicate the number of lines.
When you process the form, you loop again to insert each line:
INSERT INTO mytable (name, first name)
VALUES ("#Form ["lname"& onerow] #") ',' #Form ["Pnom" & onerow] #')
-
How to dynamically add a column to the DataGrid
Hey there everyone. Forgive me, I'm very new to this.
I use a data grid to display values analyzed in an xml file.
The application needs of 5 columns, no problem, however, if a value is present in the xml file, I need to add another column.
If I have a var defined as
var gps_present which is a string, and if the value == 'Yes' adds a column in my datagrid?
< mx:DataGrid id = "summary_grid" x = "10" y = "15" width = "500" height = "434".
dataProvider = "{summary.lastResult.phones.phone}" >
< mx:columns >
< mx:DataGridColumn headerText = "phone number" dataField = "phone number" width = "3" / >
< mx:DataGridColumn headerText = "inc_java" dataField = "inc_java" width = "3" / >
< mx:DataGridColumn headerText = "inc_sms" dataField = "inc_sms" width = "3" / >
a logic here if inc_gps == 'y '.
< mx:DataGridColumn headerText = "inc_gps" dataField = "gps" width = "3" / >
< / mx:columns >
< / mx:DataGrid >
Thank you for any advice on that.
nephish,
Yes. Sorry, displaying large blocks of code on the forums is a little tricky. Posted an example here: http://blog.flexexamples.com/2008/03/04/dynamically-adding-new-columns-to-a-datagrid-contr ol in flex /
Hope that helps,
Peter -
Classic report - add the column "select box"?
I have a classic report and you want to add a column with a check box so that the user can select several lines and perform an action on all of the lines (delete selected, for example). Looks like it should be easy and maybe integrated features, but I don't find it. Is there a standard way to do this?
Steve
APEX 5.0
Hello
to add a box to your classic report using apex_item.checkbox like this API function:
select APEX_ITEM.CHECKBOX(p_idx=>1, p_value=>DEPTNO) as select_dept, DEPTNO as DEPTNO, DNAME as DNAME, LOC as LOC from DEPT
You can access the values checked (for example in a process page)
declare v_deleted_depts number := 0; begin FOR i in 1..APEX_APPLICATION.G_F01.count LOOP v_deleted_depts := v_deleted_depts + 1; delete from dept where deptno = APEX_APPLICATION.G_F01(i); END LOOP; :P1_DEPTCOUNT := v_deleted_depts; end;
P1_DEPTCOUNT (hidden) is just for later interaction with this procedure - for example, you want to present your users with a message of success and error custom as "Deleted & P1_DEPTCOUNT. departments. »
Maybe you would like to add an option to check all checkboxes at once. If so, read this blogpost Blog of Carl Backstrom: September 2007.
Kind regards
Pavel
Edit: don't forget to toggle the leak key for special characters not your column "checkbox.
Maybe you are looking for
-
The English spelling checker is not supported in Windows Mail
Remember - this is a public forum so never post private such as e-mail or telephone information shadows! Ideas: the English in Windows mail spelling checker does not work. How can I operate? Programs that you have problems with Windows Mail Error mes
-
I don't see the option to print 13 x 19 in my printer options.
-
I have a screen: A class that extends the screen I have three Classes that contain a call to a database that returns records of ~ 50 that I fill a ListField with. The ListField is added to a different Manager according to the class A class that conta
-
How creaate a group of email addresses in outlook?
How to create a group of e-mail addresses in outlook?
-
NCLOB - the content of the files may be questioned?
We used NCLOB as data type for a column in our table. It is accessible via a form to enter text. We now want to search the text files to find a particular record.The text in a NCLOB can be questioned?Thank you for your help.