Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need
.00012 $
from 0.00012
but
1.0002 $ from 1.0002
Is this possible in postgress?
You can use something like below -
With t as
(Select 1.0002 As Value
UNION ALL
Select .00012 As Value
)
Select to_char(Value,concat('FM$999,999,999,990D',repeat('0',length(cast(Value as varchar))-2))) from t;
Below is a DB fiddle link to illustrate - https://dbfiddle.uk/?rdbms=postgres_9.5&fiddle=a8e9a3207305b011f5bf7be58ce04180
EDIT : As I thought more about the problem, I realized that the solution above would work for the examples that you have shared but it is not a generalized solution. Below would be a more general approach to solve the problem :
With t as
(Select 1.0002 As Value
UNION ALL
Select .00012 As Value
UNION ALL
Select 100.003 As Value
UNION ALL
Select 12.34456 As Value
UNION ALL
Select 5000.30 As Value
)
Select to_char(Value,concat('FM$999,999,999,990D',repeat('0',length(cast(Value as varchar))-length(cast(ROUND(Value,0) as varchar))-1))) As Amt from t;
DB fiddle link - https://dbfiddle.uk/?rdbms=postgres_9.5&fiddle=ff6f59fdd499941ee1cb1e0fc57e08ca
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
enter image description hereI would like to SELECT from a table where column uit consist value from 20 to 100 included. please find the attached pic as an example. After select by uit column, it will show the highlighted portion only (included "index", "index_","sales","return" and other 300+ columns)
for example: SELECT * FROM database.table ORDER BY or where...
Thank you very much!
enter image description here
SELECT
*
FROM
database.table
WHERE
"uit " BETWEEN 20
AND 100
The BETWEEN operator is inclusive: begin and end values are included - w3schools.com
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
Colum2
Karim_bk
Karim_bk
Karim_bk
Want result Karim
This should work
select top 10 Lastname, LEFT(Lastname, LEN(Lastname) - 3) as TrimmedVersion from tablename
Hope this will help you. In Oracle:
SELECT SUBSTR(column_name, 0, LENGTH(column_name) - 2) from table_name;
--SELECT SUBSTR('karim_bk', 0, LENGTH('karim_bk') - 2) from dual; --karim
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a quick sql data as below,
Customerid,Type
1,Adult
1,Adult
2,Adult
3,Adult
4,Teenager
4,Adult
I want the query that lists those customer no.s that do not have any other Type associated with them. For eg. 1 as only Adult associated with, same with 2. But 3 and 4 have multiple Types associated with them.
I am trying to get an output as below.
Customerid,Type
1,Adult
2,Adult
3,null
How should we tackle this.
You seem to want:
select customerid
, (case when min(type) = max(type) then min(type) end) as type
from table t
group by customerid;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a table with data like:
cust_id, acct_no, ind
123111, 1233, Y
123111, 2311, N
222111, 1112, N
222111, 2111, N
I have to get output as cust_id, 1 (a binary indicator if any of the acct under that customer is Y)
so from the above table I have to get below output.
123111 1
222111 0
A simple way to achieve this is something like:
select cust_id, max(case when ind = 'Y' then 1 else 0 end) as flag from customers group by cust_id;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can I possibly select a part of a row data in MS Sql?
ex. Charmina (Female)
All I want to select is the Female not the whole Charmina (Female)
Try this
select substring('Charmina (Female)',
charindex('(','Charmina (Female)')+1,
LEN('Charmina (Female)')-charindex('(','Charmina (Female)')-1)
or
select stuff('Charmina (Female)',1,charindex('(','Charmina (Female)')-1,'')
You may Use SUBSTRING to get sub sequences of strings
SELECT SUBSTRING( your_Raw ,start , length ) AS Alias
FROM Your_Table