[英]SQLLite SQL statement to find first non-zero of multiple columns
I have 2 rows in a table. 我在表中有2行。 Each row contains a primary key, and 5 additional columns, whose value may be 1, or 0.
每行包含一个主键和5个其他列,其值可以为1或0。
So for example one of the columns is "TermsAccepted" and another is "CopyrightAcknowledged" 例如,一列是“ TermsAccepted”,另一列是“ CopyrightAcknowledged”
Row 1's "Terms Accepted" might be 0 or 1, and row 2's "Terms Accepted" might be 0 or 1 as well. 第1行的“接受的条款”可能为0或1,第2行的“接受的条款”也可能为0或1。
I'd like to know if at least one of the rows contains a 1 for each column. 我想知道每一行中是否至少有一行包含1。 Do I have to use 5 subqueries to do this (I'd like to just have one row returned that tells me if any of the columns have 1's in them).
我是否必须使用5个子查询来执行此操作(我只想返回一行来告诉我其中是否有1列)。 It doesn't matter to me how many had 1, just so long as at least one column did.
只要有至少一列,对我来说多少就没有关系。
Hopefully that made sense. 希望这是有道理的。 How could I write a query to do this?
我如何编写查询来做到这一点? I'm using SQL Lite.
我正在使用SQL Lite。 I'm somewhat stuck.
我有些卡住。 Thanks so much!
非常感谢!
Note: I can just return both records, and then use Swift (the programming language i'm doing this in) to just parse each column in each row and look for a 0 or a 1, but I was hoping for something in SQL to make it more elegant if possible. 注意:我可以只返回两条记录,然后使用Swift(我正在使用的编程语言)来解析每一行中的每一列并寻找0或1,但是我希望在SQL中找到一些东西如果可能的话,使其更优雅。
I think this should work but if anyone could confirm that would be great, thanks! 我认为这应该可行,但是如果有人可以确认那会很好,谢谢!
SELECT
max(TermsAccepted),
max(CopyrightAcknowledged),
max(LoggedIn),
max(LockedOut),
max(AccountCopied)
FROM MyTable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.