When I use
=query('Sheet1'!B2:E, "select B,C,D,E Order By B DESC",-1 )
where D is a date column the query works. But it does not work when I try to sort "B ASC" , Why?
it works too but your output is at the end of spreadsheet (scroll all the way down). to "fix" this you can do:
=QUERY('Sheet1'!B2:E, "select B,C,D,E where B is not null order By B asc", -1)
Related
I have this query in my sheet:
=query(A2:A100, "Order by A Desc Limit 20")
I want to copy and paste it to more cells and expect it will update range and column from A2:A100 to B2:B100, C2:C100 etc.. and A in query to B, C etc.
=query(B2:B100, "Order by B Desc Limit 20")
=query(C2:C100, "Order by C Desc Limit 20")
But when I copy/paste, it only updates range, but not query.
How to implement it?
use:
=SORTN(A2:A100; 20; 1; 1; 0)
use this instead for copy-pasting w/no issues:
=query({A2:A100}, "Order by Col1 Desc Limit 20")
In order to create a specific chart, I need to look for the values of column H in reverse to which they are presented. I tried via Query:
=QUERY(H2:J, "select H order by J desc", 0)
But it returned in the wrong way as you can see:
I would like to know what would need to be adjusted. Because did not return in the exact inverse sequence of column H as it should in theory happen.
Link to Spreadsheet:
https://docs.google.com/spreadsheets/d/1ehtyuyiAiuQvQUWgMrYBreUMA94jnAliu-VcHfBFi5s/edit?usp=sharing
try:
=ARRAYFORMULA(QUERY({ROW(H2:H), H2:H},
"select Col2
where Col2 is not null
order by Col1 desc", 0))
Team,
I have an issue here, have 2 temporary table a & b with value as 5 & 6 for the respective column like a.ref1 & b.ref2.
I am trying to get these values into another SQL like
"select c.col1, d.col1,d.col2 from c join d on a.id=d.id where d.col1=(schema_name).a.ref1 or
d.col2=(schema_name).b.ref2"
I get error like
"Invalid table alias or column reference "
. any thoughts, why it behaving like this. I tried with select query to pass the temp table values but this does not work in hive .Any further assistance would be appreciated
You you can do this by using something called Common Table Expression, This will make your query perform better.
It would look like this:
WITH
refined_d AS
(
SELECT
d.id,
d.col1,
d.col2
FROM
d
INNER JOIN
(schema_name).a
ON
( (schema_name).a.ref1 = d.col1)
INNER JOIN
(schema_name).b
ON
( ( schema_name).b.ref2 = d.col2)
)
SELECT
c.col1,
d.col1,
d.col2
FROM
c
JOIN
refined_d d
ON
c.id=d.id;
I have expression with db_link to MS SQL:
select b."Str" as "State" ,a."_Fld9059" as "Date" from
"_InfoRg9050"#SQLSERVER.UISLAB.COM a INNER JOIN
"EnumTexts"#SQLSERVER.UISLAB.COM b
on a."_Fld9052RRef" = b."_IDRRef"
where a."_Fld10998" = '1104000009' and
a."_Fld10998" = to_date(max(a."_Fld9059"),'dd.mm.yyyy')
order by a."_Fld9059" desc;
I want to upload value with maximum date. Can anybody help me ?
When I run this query I get ORA-00934 error.
The immediate cause of the error you are getting is that MAX() appears in the WHERE clause. One possible workaround, which might be what you intended, would be to use a subquery in the WHERE clause to identify the maximum date:
SELECT b.Str AS State,
a._Fld9059 AS Date
FROM _InfoRg9050 a
INNER JOIN EnumTexts b
ON a._Fld9052RRef = b._IDRRef
WHERE a._Fld10998 = '1104000009' AND
a._Fld10998 = (SELECT MAX(TO_DATE(_Fld9059, 'dd.mm.yyyy')) FROM _InfoRg9050)
ORDER BY a._Fld9059 DESC
However, it is not clear why you are comparing _InfoRg9050._Fld10998 to both the string '1104000009' and a date. You will need to resolve this on your own I believe to get a meaningful result.
Thank you for your help. I got it.
SELECT b."Str" AS "State"
FROM "_InfoRg9050"#SQLSERVER.UISLAB.COM a
INNER JOIN "EnumTexts"#SQLSERVER.UISLAB.COM b
ON a."_Fld9052RRef" = b."_IDRRef"
WHERE a."_Fld10998" = '1104000009' AND
a."_Fld9059" = (select MAX(a."_Fld9059") from "_InfoRg9050"#SQLSERVER.UISLAB.COM a
INNER JOIN "EnumTexts"#SQLSERVER.UISLAB.COM b
on a."_Fld9052RRef" = b."_IDRRef"
where a."_Fld10998" = '1104000009')
ORDER BY a."_Fld9059" DESC
I created this query using HQL with Hibernate and Oracle
select c from Cat c
left join c.kittens k
where (c.location= 1 OR c.location = 2)
and (i.activo = 1)
group
by c.id,
c.name,
c.fulldescription,
c.kittens
order by count(e) desc
The problem comes with the fact that in HQL you need to specify all fields in Cat in order to perform a Group By, but fulldescription is a CLOB, and you cannot group by by a CLOB (I get a "Not a Group By Expression" error. I've seen a few solutions around for a pure SQL sentence but none for HQL.
A serious issue GROUP BY of HQL because if you specify your object in GROUP BY and in your SELECT field list behaviours are differents. In GROUP BY has considered only id field but in SELECT field list all fields are considered.
So you can use a subquery with GROUP BY to return only id from your object, so that result becomes an input for the main query, like the follow I write for you.
Pay attention there are some alias table (i and e) not defined, so this query doesn't work, but you know as fixed.
Try this:
select c2 from Cat c2
where c2.id in (
select c.id from Cat c
left join c.kittens k
where (c.location= 1 OR c.location = 2)
and (i.activo = 1) <-- who is i alias??
group by c.id)
order by count(e) desc <-- who is e alias???