英文:
Google sheets query function comparison operator '<' does not work
问题
I have a google spreadsheet with some financial information. I want to query that info for the purpose of presenting some summary information. For reasons unknown the 'less than' comparison operator (<) does not work.
Here are the records in the relevant columns:
ID Status Val1 Val2
102 Closed 25.18 39.35
103 Closed 89.90 161.35
104 Closed 83.79 110.35
105 Closed 15.17 59.35
106 Closed 85.74 84.69
107 Closed 84.03 156.69
108 Closed 85.50 131.34
109 TBD 33.38 38.3
The columns A, B, K & Z correspond to the captioned columns ID, Status, Val1, Val2.
The following query returns no records despite the fact that column Z (with the caption 'Val2') does, indeed, contain values less than 50.
=QUERY(Fin!A$4:AC,"select A,B,K,Z where B != 'Open' and Z < 50 order by A asc limit 8",-1)
Contrariwise, the following query does work. It returns the expected records with values in column Z greater than 50.
=QUERY(Fin!A$4:AC,"select A,B,K,Z where B != 'Open' and Z > 50 order by A asc limit 8",-1)
Here is the result of this query:
ID Status Val1 Val2
103 Closed 89.90 161.35
104 Closed 83.79 110.35
105 Closed 15.17 59.35
106 Closed 85.74 84.69
107 Closed 84.03 156.69
108 Closed 85.50 131.34
Good.
The following query should return all rows but returns none:
=QUERY(Fin!A$4:AC,"select A,B,K,Z where B != 'Open' order by A asc limit 8",-1)
The main problem is that the greater than comparison operator seems to work, but the less than operator does not. And, after I get that figured out, I would like to understand why the last query does not return all records.
I am mystified. Any help is appreciated.
英文:
I have a google spreadsheet with some financial information. I want to query that info for the purpose of presenting some summary information. For reasons unknown the 'less than' comparison operator (<) does not work.
Here are the records in the relevant columns:
ID Status Val1 Val2
102 Closed 25.18 39.35
103 Closed 89.90 161.35
104 Closed 83.79 110.35
105 Closed 15.17 59.35
106 Closed 85.74 84.69
107 Closed 84.03 156.69
108 Closed 85.50 131.34
109 TBD 33.38 38.3
The columns A, B, K & Z correspond to the captioned columns ID, Status, Val1, Val2.
The following query returns no records despite the fact that column Z (with the caption 'Val2') does, indeed, contain values less than 50.
=QUERY(Fin!A$4:AC,"select A,B,K,Z where B != 'Open' and Z < 50 order by A asc limit 8",-1)
Contrariwise, the following query does work. It returns the expected records with values in column Z greater than 50.
=QUERY(Fin!A$4:AC,"select A,B,K,Z where B != 'Open' and Z > 50 order by A asc limit 8",-1)
Here is the result of this query:
ID Status Val1 Val2
103 Closed 89.90 161.35
104 Closed 83.79 110.35
105 Closed 15.17 59.35
106 Closed 85.74 84.69
107 Closed 84.03 156.69
108 Closed 85.50 131.34
Good.
The following query should return all rows but returns none:
=QUERY(Fin!A$4:AC,"select A,B,K,Z where B != 'Open' order by A asc limit 8",-1)
The main problem is that the greater than comparison operator seems to work, but the less than operator does not. And, after I get that figured out, I would like to understand why the last query does not return all records.
I am mystified. Any help is appreciated.
答案1
得分: 1
给以下公式尝试一下:
=QUERY(A:D, "select A,B,C,D where (B != 'Open') and (B is not null) and (D<50) order by A limit 8", 1)
英文:
Give a try to the following formula-
=QUERY(A:D,"select A,B,C,D where (B <>'Open') and (B is not null) order by A limit 8",1)
Not equal !=
will also work.
=QUERY(A:D,"select A,B,C,D where (B !='Open') and (B is not null) order by A limit 8",1)
Problem is, you formula returning values correctly but due to limit 8
it is returning only 8 rows but they all are blanks. So, add another condition B is not null
which will filter only values removing blank cells.
And finally to filter D Column
, for your case Z Column
values less than 50
add another condition to where clause.
=QUERY(A:D,"select A,B,C,D
where (B !='Open') and (B is not null) and (D<50)
order by A
limit 8",1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论