On Wed, May 9, 2018, at 16:19, Cecil Westerhof wrote:
> I have a table where I use 'unused' to signify that a record is not yet
> used. I want to know the number of unused records (but only if there are
> unused records) and the total number of records.
>
> At the moment I implemented it like:
> SELECT *
> FROM (
> SELECT 'Not used' AS Type
> , COUNT(*) AS NoUsed
> FROM quotes
> WHERE totalUsed == 'unused'
> UNION ALL
> SELECT 'Total' AS Type
> , COUNT(*) AS NoUsed
> FROM quotes
> )
> WHERE NoUsed > 0
>
> Is this correct, or is there a better way?
Would this work?
SELECT COUNT(*) AS Total,
SUM(CASE WHEN totalUsed = 'unused' THEN 1 END) AS NotUsed
FROM quotes;
Cheers,
--
José María (Chema) Mateos
https://rinzewind.org/blog-es || https://rinzewind.org/blog-en
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users