converting int to real in sqlite
Just multiply one of the numbers by 1.0
:
SELECT something*1.0/total FROM somewhere
That will give you floating point division instead of integer division.
Convert integer to text in SQLite's SELECT query?
SQLite supports CAST and:
Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the encoding of the database connection.
So you can do things like this:
select cast(some_integer_column as text) from some_table;
Or, depending on what you're trying to do, you could just treat the numbers as strings and let SQLite coerce the types as it sees fit:
select some_int || ' pancakes' from some_table;
select some_int || '' from some_table;
Converting text to int in sqlite when querying
You need to cast in where
clause, not where you are selecting it.
string sql4 = "select seq, maxLen from abc where CAST(maxLen as INTEGER) > 30";
Also in your current cast
version it will not work since CAST
works for a single field.
For your question:
How would I also convert the text to double
cast it to REAL like:
CAST(maxLen as REAL)
How to type cast in sqlite3
The ::
syntax is PostgreSQL specific. You could use ANSI standard instead:
SELECT CAST(b AS INT) + 2 AS alias
FROM A
SqlFiddleDemo
.0 appended when converting number to text in SQLITE
You can check whether removing the fractional digits would change the value:
SELECT CAST(CASE WHEN CAST(orderid AS INTEGER) = orderid
THEN CAST(orderid AS INTEGER)
ELSE orderid
END AS TEXT)
FROM orders;
Related Topics
What Is the Purpose of Order by 1 in SQL Select Statement
Copy Table Structure into New Table
How to Copy a Row from One SQL Server Table to Another
How to Decrease the Size of My SQL Server Log File
How to Insert Data into a MySQL View
SQL Server - Where Is "Sys.Functions"
How to Use Multiple with Statements in One Postgresql Query
How to Setup a Linked Server to an Oracle Database on SQL 2000/2005
SQL Server Table Creation Date Query
When Should I Use Primary Key or Index
Converting Int to Real in SQLite
How to Simulate Deadlock on SQL Server
In Postgresql, Force Unique on Combination of Two Columns
Rails Way to Reset Seed on Id Field
Group by and Count Using Activerecord