I would like to rename certain data from an oracle table. Lets assume the data in table "Random Items" has the form
Day Item Total
12/3 102 12
12/3 423 28
12/4 102 48
I would like to rename the Item number to a specific string so when I grab the data from the table the output will look like
Day Item Total
12/3 Shoe 12
12/3 Orange 28
12/4 Shoe 48
so Shoe = 102 and Orange = 423
I have no writing writes to the tables. I've looked at commands such as rename, synonym and replace but they all rename a specific table or column. I would like to reverence the data in the table.
Thank you
select day, case ITEM when 102 then 'shoe'
when 423 then 'orange'
end itemname, total
from items
try using decode like:
select day, decode(item, '102', 'Shoe', '423', 'Orange',...), total from items
Related
lets say that i have table like this
ITEMNAME JANUARY FEBRUARY
Table 20 100
Chair 30 50
and i want to show it like this
ITEMNAME JANUARY FEBRUARY SUM
Table 20 100 120
Chair 30 50 80
the question is how to show that table with query?
You can do it like this
SELECT item, january, february, (january+february) AS sum
FROM table
It hasn't been tested yet, but I think it works
I have built a dynamic crosstab query where the user selects options from multiple combo boxes and then I use VBA to update the SQL for the cross tab query. It is then, in turn, displayed on a subform. My question is basically how can I programmatically (VBA or SQL, don't really care either way) add a totals row that calculates the average of each column. I know how to do this manually, but since the number of columns and column headings are not set, this is impractical. I would basically like to automatically set a totals row at the bottom for the average of each column regardless of the number of columns or column headers. An example of a potential case is shown below with the user inputs on top.
Group: A
Team: All
Start Date: 1/1/2014
End Date: 5/31/2014
Query Type: Monthly
Name 2014-Jan 2014-Feb 2014-Mar 2014-Apr 2014-May
John Doe1 1 2 3 4 5
John Doe2 2 2 2 2 2
John Doe3 1 5 9 13 17
John Doe4 2 10 18 26 34
John Doe5 1 8 15 22 29
John Doe6 2 12 22 32 42
John Doe7 1 15 29 43 57
John Doe8 2 14 26 38 50
John Doe9 1 12 23 34 45
Total (Avg): 1.44 8.89 16.33 23.78 31.22
I am trying the generate the bottom "Totals" row programmatically without knowing the column count ahead of time and without manually inserting totals via the ribbon.
You can use a pivot table on a simple select query.
Doesn't the crosstab query do that for you?
https://support.office.com/en-us/article/Make-summary-data-easier-to-read-by-using-a-crosstab-query-8465B89C-2FF2-4CC8-BA60-2CD8484667E8
http://www.fmsinc.com/microsoftAccess/query/crosstab-report/index.html
Although crosstab queries are somewhat limited in their power, you can certainly create another query to do a basic average of the crosstab query you just created.
I'm using Crystal Reports 2008. And I have database access 2003 "myclass" with table "Class" an output of like this:
----------
Date Total
12/2015 100
01/2016 115
02/2016 150
03/2016 180
----------
Now, my question how formula for "Previous_Total" the output should be:
----------
Date Total Previous_Total
12/2015 100 0 ----> 0 because no data before
01/2016 115 100 -----> this form total
02/2016 150 215 -----> 100 + 115
03/2016 180 365 -----> 100 + 115 + 150
----------
if i'm use record selection ex sample: {Class.date}>=Date("02/2016") And {Class.date}<=Date("03/2016")
i want to show in the report like this:
----------
Date Total Previous_Total
02/2016 150 215
----------
After trying 3 days, my case is done....
create group Date as "In specified order" then setting to "is in the period " and I'm selecting AllDatesFromToday (Position group is down column Page Header).
create group Total as "in ascending order" (Position group is up column Details).
Hide column details
insert Summary Date as "Maximum"
insert summary Total as "Sum"
drag max total to group Date, drag sum total to group Date
Finally create formula Previous_Total:
Sum ({MyClass.Total}, {MyClass.Date}, "daily")-{MyClass.Total}
Drag formula Previous_Total to group Date.
I try to test... Klik Menu Report, Selection Formulas, Record...
{MyClass.Date}<=date("02/2016")
Save, press F5 to refresh data and DONE...
Thank everybody for reply.... :)
Please bear with me, as I have very little SQL knowledge.
Basically, I would like to be able to generate a list of totals from a table that holds data for various locations. Within the table, each row references the location's ID and has a value:
ID LocationID Value
___ ____________ _______
1 11 500
2 11 400
3 12 500
4 12 600
5 12 300
6 13 400
7 13 500
I would like to produce a list with each locationID and the total of all values within the "data" table.
Desired output:
LocationID Total
__________ _____
11 900
12 1400
13 900
I am sorry if I have explained it poorly... Like I said, I have very limited knowledge of SQL so I simply do not know where to start. If somebody could simply point me in the correct direction I would be very grateful.
Try below:
SELECT LocationID, sum(value) AS Total
FROM data
GROUP BY LocationID;
I am assuming data is your table name and LocationID and value are column names.
I have a table product, pick_qty, shortfall, location, loc_qty
Product Picked Qty Shortfall Location Location Qty
1742 4 58 1 15
1742 4 58 2 20
1742 4 58 3 15
1742 4 58 4 20
1742 4 58 5 20
1742 4 58 6 20
1742 4 58 7 15
1742 4 58 8 15
1742 4 58 9 15
1742 4 58 10 20
I want a report to loop around and show the number of locations and the quantity I need to drop to fulfil the shortfall for replenishment. So the report would look like this.
Product Picked Qty Shortfall Location Location Qty
1742 4 58 1 15
1742 4 58 2 20
1742 4 58 3 15
1742 4 58 4 20
Note that it is best not to think about SQL "looping through a table" and instead to think about it as operating on some subset of the rows in a table.
What it sounds like you need to do is create a running total that tells how many of the item you would have if you were to take all of them from a location and all of the locations that came before the current location and then check to see if that would give you enough of the item to fulfill the shortfall.
Based on your example data, the following query would work, though if Locations aren't actually numerics then you would need to add a row number column and tweak the query a bit to use the row number instead of the Location Number; It would still be very similar to the query below.
SELECT
Totals.Product, Totals.PickedQty, Totals.ShortFall, Totals.Location, Totals.LocationQty
FROM (
SELECT
TheTable.Product, TheTable.PickedQty, TheTable.ShortFall,
TheTable.Location, TheTable.LocationQty, SUM(ForRunningTotal.LocationQty) AS RunningTotal
FROM TheTable
JOIN TheTable ForRunningTotal ON TheTable.Product = ForRunningTotal.Product
AND TheTable.Location >= ForRunningTotal.Location
GROUP BY TheTable.Product, TheTable.PickedQty, TheTable.ShortFall, TheTable.Location, TheTable.LocationQty
) Totals
-- Note you could also change the join above so the running total is actually the count of only the rows above,
-- not including the current row; Then the WHERE clause below could be "Totals.RunningTotal < Totals.ShortFall".
-- I liked RunningTotal as the sum of this row and all prior, it seems more appropriate to me.
WHERE Totals.RunningTotal - Totals.LocationQty <= Totals.ShortFall
AND Totals.LocationQty > 0
Also - as long as you are reading my answer, an unrelated side-note: Based on the data you showed above, your database schema isn't normalized as far as it could be. It seems like the Picked Quantity and the ShortFall actually depend only on the Product, so that would be a table of its own, and then the Location Quantity depends on the Product and Location, so that would be a table of its own. I'm pointing it out because if your data contained different Picked Quantities/ShortFall for a single product, then the above query would break; This situation would be impossible with the normalized tables I mentioned.