Google Sheets查询函数中的比较运算符’<'不起作用。

huangapple go评论72阅读模式
英文:

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,&quot;select A,B,K,Z where B != &#39;Open&#39; and Z &lt; 50 order by A asc limit 8&quot;,-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,&quot;select A,B,K,Z where B != &#39;Open&#39; and Z &gt; 50 order by A asc limit 8&quot;,-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,&quot;select A,B,K,Z where B != &#39;Open&#39; order by A asc limit 8&quot;,-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,&quot;select A,B,C,D where (B &lt;&gt;&#39;Open&#39;) and (B is not null) order by A limit 8&quot;,1)

Not equal != will also work.

=QUERY(A:D,&quot;select A,B,C,D where (B !=&#39;Open&#39;) and (B is not null) order by A limit 8&quot;,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,&quot;select A,B,C,D 
where (B !=&#39;Open&#39;) and (B is not null) and (D&lt;50) 
order by A 
limit 8&quot;,1)

Google Sheets查询函数中的比较运算符’<'不起作用。

huangapple
  • 本文由 发表于 2023年5月17日 10:13:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268144.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定