Remove the Decimal values
select cast(val as integer),val from table
and I tried round that is also not working pls tell me the way to solve this.
select ROUND(2.9,0) from dual
24 23.8331134259259
31 30.8322222222222
31 30.8321990740741
31 31.1120023148148
31 31.1119791666667
28 28.0590046296296
31 31.1177314814815
4 4.05344907407407
4 4.03957175925926
14 13.7137731481481
5 4.79490740740741
5 4.79490740740741
5 4.79489583333333
5 4.79488425925926
Expected Output :
23 23.8331134259259
30 30.8322222222222
30 30.8321990740741
30 31.1120023148148
30 31.1119791666667
28 28.0590046296296
31 31.1177314814815
4 4.05344907407407
4 4.03957175925926
13 13.7137731481481
4 4.79490740740741
4 4.79490740740741
4 4.79489583333333
4 4.79488425925926
Hi try truncate function
TRUNC( number, [ decimal_places ] )
Are you looking for FLOOR?
FLOOR returns the largest integer equal to or less than n. The number n can always be written as the sum of an integer k and a positive fraction f such that 0 <= f < 1 and n = k + f. The value of FLOOR is the integer k. Thus, the value of FLOOR is n itself if and only if n is precisely an integer.
Just select FLOOR(2.9,0) from dual
Related
I have next table
points:
min max level
0 5 1
6 10 2
11 15 3
16 20 4
and I need to extract level according points. If I have 7 points then level will be 2 and query is next:
select level
from points
where 7 > min
AND 7 < max
what I need is get highest level if points are more then 20, for example if I have 35 points level should be 4. How I can do it?
Set max in the last row to null:
| 16 | null | 4
And your query becomes:
SELECT level
FROM points
WHERE :score >= min
AND (:score <= max OR max is null)
Remark: it is better to define your ranges as [min,max[:
min max level
0 6 1
6 11 2
11 16 3
16 4
Then your query becomes:
SELECT level
FROM points
WHERE :score >= min
AND (:score < max OR max is null)
How can I code this 'if' conditions in GAMS?
Set j/1*10/
S/1*6/;
Parameter
b(s,j) export this from excel
U(s,j) export from excel
M(s)/1 100,2 250,3 140,4 120,5 132/ export from excel
;
table b(s,j)
1 2 3 4 5 6 7 8 9 10
1 3 40 23 12 9 52 9 14 89 33
2 0 0 42 0 11 32 11 15 3 7
3 10 20 12 9 5 30 14 5 14 5
4 0 0 0 9 0 3 8 0 13 5
5 0 10 11 32 11 0 3 1 12 1
6 12 20 2 9 15 3 14 5 14 5
;
u(s,j)=0;
u(s,j)$(b(s,j))=1;
Variable delta(j); "binary"
After solving a model I got the value of delta ( suppose delta(1)=1, delta(5)=1). Then Set A is
A(j)$(delta.l(j)=1)=Yes; (A={1,5})
I want to calculate parameter R(s) according to the following :
If there is no j in A(j) s.t. j in u(s,j) then R(s)=M(s)
Else if there is a j in A(j) s.t. j in u(s,j) then R(s)=min{b(s,j): j in A(j) , j in u(s,j) }
Then R(1)=3, R(2)=11,R(3)=5, R(4)=120, R(5)=11,R(6)=12.
Is it possible to code this ' if then ' statement only by $ utility?
Thanks
Following on from the comments, I think this should work for you.
(Create a parameter that mimics your variable delta just for demonstration:)
parameter delta(j);
delta('1') = 1;
delta('5') = 1;
With loop and if/else:
Create parameter R(s). Then, looping over s , pick the minimum of b(s,A) across set A where b(s,A) is defined if the sum of b(s,A) is not zero (i.e. if one of the set is non-zero. Else, set R(s) equal to M(s).
Note, the loop is one solution to the issue you were having with mixed dimensions. And the $(b(s,A)) needs to be on the first argument of smin(.), not on the second argument.
parameter R(s);
loop(s,
if (sum(A, b(s,A)) ne 0,
R(s) = smin(A$b(s,A), b(s,A));
else
R(s) = M(s);
);
);
With $ command only (#Lutz in comments):
R(s)$(sum(A, b(s,A)) <> 0) = smin(A$b(s,A), b(s,A));
R(s)$(sum(A, b(s,A)) = 0) = M(s);
Gives:
---- 56 PARAMETER R
1 3.000, 2 11.000, 3 5.000, 4 120.000, 5 11.000, 6 12.000
I have the following table:
----------------------------------------------
oNumber oValue1
----------------------------------------------
1 54
2 44
3 89
4 65
ff.
10 33
11 22
ff.
20 43
21 76
ff.
100 45
I want to select every 10 value in oNumber. So the result should be:
----------------------------------------------
oNumber oValue1
----------------------------------------------
10 33
20 43
ff.
100 45
Also, oNumber is not a sequence number. It's just a value. Even it isn't a sequence number, 10, 20, 30 and so on will always appear under oNumber field.
Does anyone know how is the tsql for this case?
Thank you.
select * from table where oNumber % 10 = 0
https://msdn.microsoft.com/en-us/library/ms190279.aspx
Use the "Modulo" operator - %. So in this case, the answer would be something like:
SELECT * FROM table WHERE oNumber % 10 = 0
This will only load if oNumber is a number divisible by ten (and therefore has a remainder zero).
In the case you simply want multiples of 10, then just use the modulo operator as stated by Daniel and Ian.
select *
from table
where oNumber % 10 = 0;
However, I felt that you could be alluding to the fact that you want to get every 10th item in your list. If that's the case, which it may be not, you would simply just sequence your set based on oNumber and use the modulo operator.
select *
from (
select *,
RowNum = row_number() over (order by oNumber)
from table) a
where RowNum % 10 = 0;
Let's assume we have the following:
A
1 10
2 20
3 30
4 20
5 10
6 30
7 20
8
9
10 =(AVERAGE(A1:A7)
11 4
12 6
I would like to be able to find a way to calculate the Average of A1-A7 into cell A10 while excluding row range defined in A11 and A12. That is, according to the above setup the result should be 20:
((10 + 20 + 30 + 20) / 4) = 20
because if rows 4,5 and 6 are excluded what's left is rows 1,2,3,7 to be averaged.
Two other options:
=AVERAGE(FILTER(A1:A7,ISNA(MATCH(ROW(A1:A7),A11:A12,0))))
=ArrayFormula(AVERAGEIF(MATCH(ROW(A1:A7),A11:A12,0),NA(),A1:A7))
Seems to meet your requirement, though not flexible:
=(sum(A1:A7)-indirect("A"&A11)-indirect("A"&A12))/(count(A1:A7)-2)
Adjust re misunderstanding of requirements:
=(SUM(A1:A7)-SUM(INDIRECT("A"&A11&":A"&A12)))/(COUNT(A1:A7)-A12+A11-1)
How I can calculate bit length of an integer in Oracle's PL/SQL?
I would like to get something like cast INT to BIT STRING and then LENGTH( LTRIM(BIT STRING, '0') )'
you can use the following formula to get the number of characters of the binary representation of an integer n (n>0):
ceil(log(2, n + 1))
SQL> SELECT n, ceil(log(2, n + 1)) num_of_char
2 FROM (SELECT ROWNUM n FROM dual CONNECT BY LEVEL <= 64);
N NUM_OF_CHAR
---------- -----------
1 1
2 2
3 2
4 3
5 3
6 3
7 3
8 4
[...]
15 4
16 5
[...]
31 5
32 6
[...]
63 6
64 7