SQLITE PERCENTAGE

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SQLITE PERCENTAGE

frknozdmr01
Hi, I need to find the percent of passengers survived? (total). How do you do
it? I tried the comment below but it did not work.

SELECT
    SUM(CASE WHEN survived=1 THEN 1.0 ELSE 0.0 END) /
        CAST(COUNT(*) AS FLOAT)*100
            AS tot_pct_survived
FROM passengers;


This is the table;

CREATE TABLE passengers (
    id INTEGER NOT NULL,
    lname TEXT,
    title TEXT,
    class TEXT,
    age FLOAT,
    sex TEXT,
    survived INTEGER,
    code INTEGER
);




--
Sent from: http://sqlite.1065341.n5.nabble.com/
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQLITE PERCENTAGE

Radovan Antloga
select 100.0 * sum(survived) / count(*) as tot_pct_survived
FROM passengers

Regards
Radovan

frknozdmr01 je 26.09.2018 ob 3:03 napisal:

> Hi, I need to find the percent of passengers survived? (total). How do you do
> it? I tried the comment below but it did not work.
>
> SELECT
>      SUM(CASE WHEN survived=1 THEN 1.0 ELSE 0.0 END) /
>          CAST(COUNT(*) AS FLOAT)*100
>              AS tot_pct_survived
> FROM passengers;
>
>
> This is the table;
>
> CREATE TABLE passengers (
>      id INTEGER NOT NULL,
>      lname TEXT,
>      title TEXT,
>      class TEXT,
>      age FLOAT,
>      sex TEXT,
>      survived INTEGER,
>      code INTEGER
> );
>
>
>
>
> --
> Sent from: http://sqlite.1065341.n5.nabble.com/
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users