'Limiting SQL result with query
I am trying to print the table results on the basis of output generated by another table.
so, lets say my table II produces an integer output of some value then I want to use that value to limit my results for table I.
I am unable to make this query work. I wrote this but cant see the problem. Is there any other way of writing this?
I read somewhere on SO that subquery in limit is not allowed but I am not sure.
select *
from stage_II_final_suzuki_1648155456 `
limit ( select count(*)*0.80
from tmp.stage_II_final_suzuki_1648155456
);
I want to correct the syntax for compiler
ERROR> Failed validation Syntax error: Unexpected "(" at [31:11]
Solution 1:[1]
It appears that Google Ads Data Hub uses BigQuery SQL. The syntax for LIMIT accepts a number (literal constant); you can't use any expression that needs evaluation. It does support a ROW_NUMBER() function though, and you can try:
select *
from (
select s1.*, row_number() over() as rn
from stage_II_final_suzuki_1648155456 s1 `
) s2
where s2.rn <= ( select count(*)*0.80
from tmp.stage_II_final_suzuki_1648155456
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
