how to query exact integer data in redis - redis

I have redis data like this
HMSET cars:1 make Ferrari model 458 color red topSpeed 202
HMSET cars:2 make Porsche model 555 color yellow topSpeed 300
ZADD topSpeed 202 1
ZADD topSpeed 300 2
Range Query : ZRANGEBYSCORE topSpeed 200 300
So how to query exact topSpeed like 202 ?

ZRANGEBYSCORE topSpeed 202 202
From the documentation:
Returns all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max).

Related

How to find the right budget value into the activities in Tableau (Relationship)

I have related two custom sql query in Tableau (via making relationship)
The outcome of the queries looks like :
Q1 : (It shows the starting time of the valid budget.If a user has multiple rows in this table, it means his/her budget has been updated with new amount)
id_user
budgete_start_date
budget_amount
1234
06-11-2021
120
1234
06-07-2022
200
56789
06-01-2022
1200
56789
06-07-2022
2000
643
05-05-2022
30
Q2 :(It shows the budget usage)
id_user
budgete_usage_date
amount_usage
1234
01-12-2021
50
1234
05-08-2022
100
56789
10-02-2022
60
56789
07-08-2022
500
643
05-07-2022
17
I need to find a way to create the following view to know what was the valid budget at
budgete_usage_date.
id_user
budgete_usage_date
amount_usage
valid budget
1234
01-12-2021
50
120
1234
05-08-2022
100
200
56789
10-02-2022
60
1200
56789
07-08-2022
500
2000
643
05-07-2022
17
30
How can I do that with calculated field in Tableau (with db made by relationship)?
If that's not possible, how can I do that directly in query? (changing the relationship to a single query)

Proc Optmodel SAS Variable not unique

I am using proc optmodel to solve a problem in which several items must be priced the same within the same location (let's say they are different colors of same product and are not currently priced the same). I know that volume will increase/decrease depending on direction of price change, and I have some MIN/MAX constraints as well.
The problem I am running into is that the procedure is only reading one group of unique SKUs....I think because they repeat. How can I get the procedure to optimize all unique combinations of SKU/LOCATION? I tried just changing the item numbers, which of course works, but is not practical for my business solution. Thanks.
data input_data;
input SKU DESC $ LOCATION $ OLD_PRICE MIN MAX LIFT OLD_UNITS;
cards;
111 black NY 12.99 10 15 1.3 100
222 white NY 13.45 11 15 .9 150
333 red NY 13.29 13 15 1.6 200
111 black DC 11.75 10 14 1.2 300
222 white DC 11.75 10 14 1.5 100
333 red DC 11.99 10 14 1.7 140
111 black LA 14.21 12 17 2.0 600
222 white LA 14.79 14 17 1.5 500
333 red LA 15.99 13 17 .3 200
444 orange LA 14.11 12 17 .6 300
;
run;
proc optmodel;
set<num> SKU;
string LOCATION{SKU};
string DESC{SKU};
set LOCATIONS = setof{i in SKU} LOCATION[i];
set SKUperLOCATION{gi in LOCATIONS} = {i in SKU: LOCATION[i] = gi};
number OLD_PRICE{SKU};
number MIN{SKU};
number MAX{SKU};
var NEW_PRICE{gi in LOCATIONs} >= max{i in SKUperLOCATION[gi]} MIN[i] <= min{i in SKUperLOCATION[gi]} MAX[i];
impvar NEW_PRICEbySKU{i in SKU} = NEW_PRICE[LOCATION[i]];
number LIFT{SKU};
number OLD_UNITS{SKU};
read data input_data into
SKU=[SKU]
DESC
LOCATION
OLD_PRICE
MIN
MAX
LIFT
OLD_UNITS;
max sales=sum{gi in LOCATIONs}
sum{i in SKUperLOCATION[gi]}
(NEW_PRICE[gi])*(1-(NEW_PRICE[gi]-OLD_PRICE[i])*LIFT[i]/OLD_PRICE[i])*OLD_UNITS[i];
expand;
solve;
create data results_FAM_maxsales
from [SKU]={SKU}
DESC
LOCATION
OLD_PRICE
NEW_PRICE=NEW_PRICEbySKU
MIN
MAX
LIFT
OLD_UNITS;
print NEW_PRICE sales;
quit;
One way would be to set your unique key to be SKU & Location. I haven't used OPTMODEL in a while, but something like this should work.
set<num,str> SKU_Loc;
num old_price{SKU_Loc};
<code>
read data input_data into SKU_Loc = [SKU Location];
<code>
Then change the rest of the code to reference the unique combination of SKU & location.

Oracle select query based on multiple conditions

MESSAGE_ID GROUP_ID REV_NO
100 200 1
101 201 1
102 202 1
103 203 1
104 204 1
105 200 2
106 201 2
107 202 2
108 203 2
109 204 2
110 205 2
First I want to select all group ID's and their correpsponding lowest revision number.
Then I want select first X message ID's (Controllable X input) with condition that it should contain all the revisions of of any selected group. For e.g if I select first 5 messages by rownum then all revisions of group_id 200 is not selected.
Hope I made it clear.

SQL Delete Duplicates with greater difference between two columns

I have a table something similar to :
ID Value1 Value2
122 800 1600
122 800 1800
133 700 1500
154 800 1800
133 700 1500
188 700 1400
176 900 1500
From this table I want to delete the duplicates (ID of 122 and 133) which have a greater difference between value2 and value1.
This means that where ID is 122 I want to keep the first row (1800-800>1600-800)
This means that where ID is 133 I want to keep either one because they both have the same difference.
ID Value1 Value2
122 800 1600
122 800 1800 <------delete this row
133 700 1500 <------delete either this row or the other identical row
154 800 1800
133 700 1500 <------delete either this row or the other identical row
188 700 1400
176 900 1500
It is on a much larger scale that this, so I cant just individually delete records.
Is there a way to write a statement that will delete all duplicates from my table where Value2 - Value1 is greater than Value2 - Value1 for its duplicate?
SQL Server has this great feature of updatable CTEs and subqueries. So, you can do this as:
with todelete as (
select t.*,
row_number() over (partition by id order by value2 - value1) as diff_seqnum
from table t
)
delete from todelete
where diff_seqnum > 1;
That is, enumerate the rows for each id based on the difference in the two values. Then, only keep the rows where the sequence number is 1.

SQL query to get maximum of all maximum values per customer

I'm struggling with this specific Access 2010 SQL query for quite some time now. Let me first show you what my table looks like:
customerID value
123456789 100
123456789 -100
123456789 300
123456789 -300
123456789 150
123456789 -150
123456789 200
123456789 200
987654321 500
987654321 -500
987654321 200
987654321 -200
987654321 210
987654321 210
You see I have multiple entries for one customerID with several values. These values can be positive and negative. Negative values represent corrections so the corresponding positive value "gets nulled".
What I need to query now is the maximum value of all maximum values per customerID. In the example above, the maximum value of customerID 123456789 is 200, because all other values on this customerID annul each other. The maximum value on customerID 987654321 hence is 210.
Ultimately my query should return the value of 210 as the maximum out of all maximum values per customerID that didn't get corrected/anulled by negative values.
Can you please help me with this?
Edit: Added (duplicate) values 200 and 210 to both customerIDs to make clear that a SUM() wont work here.
Edit #2: Here's some (nearly) real life data: http://pastebin.com/TbNRTw5A
I don't know if this would be your answer, it's just assuming that all negative values have 1 corresponding equal positive value paired up.
SELECT CustomerID, SUM(Stack1.Value) FROM Stack1
GROUP BY CustomerID
So the result would be:
CustomerID Value
123456789 200
987654321 210
Hope this helps
How about this?
WITH tmpPositive AS (SELECT
Stack1.CustomerID, Stack1.Value FROM Stack1 WHERE Stack1.Value > 0),
tmpNegative AS (SELECT
Stack1.CustomerID, Stack1.Value FROM Stack1 WHERE Stack1.Value < 0)
SELECT tmpPositive.CustomerID, MAX(tmpPositive.Value) AS MaxValue FROM tmpPositive
LEFT OUTER JOIN tmpNegative
ON tmpPositive.CustomerID = tmpNegative.CustomerID AND
-tmpPositive.Value = tmpNegative.Value
WHERE tmpNegative.CustomerID IS NULL
GROUP BY tmpPositive.CustomerID;
Here's the test data:
CustomerID Value
---------------------
123456789 100
123456789 -100
123456789 300
123456789 -300
123456789 150
123456789 -150
123456789 200
987654321 500
987654321 -500
987654321 200
987654321 -200
987654321 210
123456789 200
123456789 110
987654321 1250
And the result I have for above query.
CustomerID MaxValue
--------------------
123456789 200
987654321 1250