How to structure a db table to store ranges like 0;20;40;60;80 or 0;50;100;150;200;250;... so on - oracle

I want to store the below range in a table, the number of items in template01 is 6, second is 4. How can we structure the table to store this information. Displaying these values as comma separated or having one column for each range values stated would be my last option. Can you help on how to structure the table/tables to store the below said information.
Template01 0 10 20 30 40 50
Template02 0 50 100 150
Template03 0 100 200 300 400 500 600
Basically, I want to store these ranges as templates and use it later for saying if the luggage weight is from 0 - 10, it will cost $5 per Kg, if its 10 - 20, it will cost $4.8 per Kg etc
This is how the template will be used,
Domain: XYZ
Template01 0 10 20 30 40 50
Increment01% 125% 120% 115% 110% 105% 100%
Domain: ABC, am using or picking the same template 'Template01' but Increment%
will be different for different domain, hence
Template01 0 10 20 30 40 50
Increment02% 150% 140% 130% 120% 110% 100%
Idea is, I want to store Template of weight breaks and later I want to associate with different Increment%. Thus when the user chooses a weight break template, all the increment% values applicable or configured for that template can be shown for the user to choose one.
Template01 0 10 20 30 40 50
Increment01% 125% 120% 115% 110% 105% 100% [Choice 1]
Increment02% 150% 140% 130% 120% 110% 100% [Choice 2]

Standard approach is:
Template_Name Weight_From Weight_To Price
------------- ----------- --------- -----
Template01 0 10 5
Template01 10 20 4.8
...
Template01 40 50 ...
Template01 50 (null) ...
Template02 0 50 ...
...
Template03 500 600 ...
Template03 600 (null) ...

For a normalised schema you'd need to have tables for the Template, for the Increment, for the Template Weights, and for the Increment Factors.
create table luggage_weight_template (
luggage_weight_template_id number primary key,
template_name varchar2(100) unique);
create table luggage_increment (
luggage_increment_id number primary key,
increment_name varchar2(100),
luggage_weight_template_id references luggage_weight_template(luggage_weight_template_id));
create table template_weight (
template_weight_id number primary key,
luggage_weight_template_id references luggage_weight_template(luggage_weight_template_id),
weight_from number not null);
create table increment_factor (
increment_factor number primary key,
increment_id references luggage_increment(luggage_increment_id),
template_weight_id references template_weight(template_weight_id));

Related

Index column not resetting after I apply filter in Dax?

I have table which shows time difference between different types of ID's for when an alert is given. The time since prev will say when the next alert is on the device ID.
my table looks like this:
Time Device ID Type TimeSincePrev(seconds) index
22.1.21 04:02:04 12 None 0 1
22.1.21 04:24:07 13 low 1320 2
22.1.21 04:26:04 14 medium 120 3
......
...
......
...
...
However When I filter by deviceID, the indexes will not reset to 1,2,3...., instead, it will go to a random number, causing the timesinceprev alert to be wrong. How do I correct so that index is correct, hopefully correcting the TimeSincePrev column. Also if there is a way to get TimeSincePrev to show seconds via the the seconds and not just via the minute like it is now
This is what the query for the index column looks like:
index= COUNTROWS(FILTER(VALUES('Table'[Time]),
'Table'[Time]<EARLIER('Table'[Time])
))+1
Here is how TimeSincePrev:
TimeSincePrev= IF(DATEDIFF(LOOKUPVALUE('Table'[Time],'Table'[index],
'Table'[index]-1),MINUTE)>720,BLANK(),DATEDIFF(LOOKUPVALUE('Table'[Time],
'Table'[index],'Table'[index]-1),'Table'[Time],MINUTE))*60
How do I get it so when I filter by device ID the indexes don't mess up like this:
Time Device ID Type TimeSincePrev(seconds) index
22.1.21 04:02:04 12 None 0 6
22.1.21 04:24:07 12 low 1320 3
22.1.21 04:26:04 12 medium 120 1
22.1.21 04:02:04 12 None 0 2
22.1.21 04:24:07 12 low 1320 4
22.1.21 04:26:04 12 medium 120 5
......
...
......
...
...
Are you using a column for this? If so, you need to create a measure that handles the indexing instead.
Columns are re-calculated only at refresh time (when you refresh the dataset), NOT at query time (when you click on slicers). The column cannot respond to your selected slicer value and calculate on the fly.

DAX-How to achieve a year-to-date per category?

My problem is the following:
I have a table like this one below:
Date Category Value Movment Value
2019-01-01 105 1000 1000
2019-02-05 110 1200 200
2019-03-25 100 800 -400
2019-03-28 100 700 -100
2019-04-15 95 1300 600
To get the value at date, I can calculate a year-to-date on the Movment Value column (because the Value column is not additive with respect to Date column).
Things get worse when I filter on Category column. The year-to-date gives me these values per category which is correct:
Category: 95 100 105 110
YTD : 600 -500 1000 200
But the result I am looking for is:
Category: 95 100 105 110
YTD : 1300 700 1000 1200
What I tried is this formula:
IF(NOT(ISFILTERED([Category])); [Movment Value YTD]; [Movment Value Reset Per Category YTD]),
where [Movment Value Reset Per Category] is the year-to-date of reset movment, i.e.
Date Category Value Movment Value Movment Value Per Category
2019-01-01 105 1000 1000 1000
2019-02-05 110 1200 200 1200
2019-03-25 100 800 -400 800
2019-03-28 100 700 -100 -100
2019-04-15 95 1300 600 1300
It works, but if we use multiple dimensions to filter on, it could become very complicated to manage.
Do you have an idea, how I can achieve this "special" YTD per category without having to manage all cases ?
Thank you for your inputs.
Marco

Deleting opposite duplicates in Oracle SQL

I have some issues that I hope you can lend a helping hand towards.
So I have some data with opposite value, for example:
Amount Type ID
10000 10 25
-10000 10 25
20000 11 30
30000 12 49
-30000 12 49
Sorry for the ugly table.
But how can I delete the lines where the amount cancelled out? I would like the ones with 10000 and -10000 to be deleted. But I wont know the specific type and id number. (30000 and -30000 is the same issue).
Any ideas? I've been searching forever, but can only find how to remove a duplicate row, and not both rows.
Hope it makes sense :)
Update. Thanks for the solutions so far! :)
There can be more than 1:1 in the amount column, but those wouldn't identical Type and ID. For exampel could a 6th entry look like this:
Amount Type ID
10000 10 25
-10000 10 25
20000 11 30
30000 12 49
-30000 12 49
10000 31 42
And the last one should not be deleted :) Hope it makes sense now.
On the basis only of the limited information provided...
DELETE x
FROM my_table x
JOIN my_table y
ON y.id = x.id
AND y.type = x.type
AND y.amount = x.amount * -1;

Sum Column At Each Value Change of another field in foxpro

Sum Column At Each Value Change of another field in foxpro. How can I get the additive column? I was able to do a running total but for all the items how can I get it to start at each item change?
E.g.
Item Number QTY ADDITIVE
1045 50 50
1045 25 75
1045 35 110
2045 50 50
2045 50 100
2045 25 125
3056 30 30
3056 30 60
3056 30 90
It looks like simple additive, but how are you planning on storing and presenting to the end-user the results... in a grid or just final running total per individual item? It looks like this might represent sales order item / qty sold. I would probably query into a read/write cursor ordered by item, then apply a scan loop to update each one... something like.
select ItemNumber, Qty, 000000 as RunningTotal ;
from YourTable ;
order by ItemNumber ;
into cursor C_Sample readwrite
lastItem = ""
runTotal = 0
scan
*/ If different item, reset running total back to zero
if lastItem != ItemNumber
runTotal = 0
endif
*/ Update running total
runTotal = runTotal + Qty
*/ Update the record column
replace RunningTotal with runTotal
*/ preserve the ID we just processed for comparison to next record
lastItem = ItemNumber
endscan
*/ Done...

update from temp table to original table

I have two tables one is original table and second one is temp table. Temp table having the correct record. Unique column is cust_id. My table structure is
Customer table
cust_id amount
12 100
13 120
14 130
15 250
20 70
25 110
28 900
temp table
cust_id amount
12 300
13 190
14 110
15 240
20 30
25 210
28 500
I want to update the record from temp table to customer orignal table using customer id.
It can be done using merge statement.
merge into original_table ot
using temp_table tp
on (ot.cust_id = tp.cust_id)
when matched
then update set ot.amount = tp. amount

Resources