I'm trying to import any row from the URL where column 1 contains the string 6293. When I execute this query all I get is the first row from the URL which does not contain the string 6293. BTW if I change the "where 1" clause to "where col1" I get an error. What am I doing wrong?
=query(importrange("URL","Cost Per SKU!a1:q1000"),"select * where 1 = '6293'")
try:
=QUERY(IMPORTRANGE("URL", "Cost Per SKU!A1:Q1000"),
"where Col1 = '6293'")
or:
=QUERY(IMPORTRANGE("URL", "Cost Per SKU!A1:Q1000"),
"where Col1 = 6293")
Related
Is there a way to pass the result of a query in another query in Google Sheets?
My use case example
=QUERY(form;"select * where D like here is where i need my result of another query";1)")"
the other query --> QUERY(another_range;"select * ";0)
Thanks in advance
use:
=QUERY(B2:D; "where B = date '"&TEXT(G2; "yyyy-mm-dd")&"'"; 1)
or if you want it hardcoded:
=QUERY(B2:D; "where B = date '2021-02-10'"; 1)
Need a help regarding QueryDsl using BooleanExpression. Find the requirement below.
I have Enquiry and Followup table. OneToMany mapping in between them. 1 Enquiry having many followup.
Suppose i have 5 enquiries. for each enquiry i have 3 followup.
Expectation is ..i need last record of followup for each enquiry.
Please find the different ways i have tried.
QBuyerFollowUp qBuyerfollowup = QBuyerFollowUp.buyerFollowUp;
ListPath<BuyerFollowUp, QBuyerFollowUp> followUpList = qBuyerEnquiry.followUpList;
BooleanExpression expression = commonExpression.and(new JPAQuery<>().select(qBuyerfollowup.nextDate).from(qBuyerfollowup)
.where(qBuyerfollowup.eq(followUpList.any()))
.orderBy(qBuyerfollowup.followUpId.desc()).limit(1).eq(new Date());
please ignore commonExpression which is an another expression.
Error: Subquery returns more than 1 row
BooleanExpression expression = followUpList.any().followUpId.in(new JPAQuery<QBuyerFollowUp>().select(qBuyerfollowup.followUpId.max())
.from(qBuyerfollowup).groupBy(qBuyerfollowup.buyerEnquiry.id)
.having(qBuyerfollowup.nextDate.eq(dateFormat.parse(dateFormat.format(new Date())))));
Error: unknown column nextDate.
Here generated query is:
select count(buyerenqui0_.id) as col_0_0_ from buyer_enquiry buyerenqui0_ where
buyerenqui0_.assigned_to= 79 and
(buyerenqui0_.created_at between "2020-05-01 00:00:00" and "2020-05-31 23:59:59") and buyerenqui0_.enq_status<> "Dropped" and
not ( not (exists (select followupli1_.id from buyer_followup followupli1_ where buyerenqui0_.id=followupli1_.buyer_enquiry_id)))
and (exists (select 1 from buyer_followup followupli2_ where buyerenqui0_.id=followupli2_.buyer_enquiry_id and
(followupli2_.id in (select max(a.id) from buyer_followup a group by a.buyer_enquiry_id having date(a.next_date)=date(now())))));
solution: If will remove alias name 'a' from this query
select max(a.id) from buyer_followup a group by a.buyer_enquiry_id having date(a.next_date)=date(now())))
it is working fine.
But we don't have any control on this because alias name is generated by Spring.
You can't join subqueries in JPQL, but you can project them, which should be sufficient in this case:
QInquiry inquiry = QInquiry.inquiry;
QFollowup followup = QFollowup.followup;
Map<Inquiry, Followup> results = query().from(inquiry)
.transform(GroupBy.groupBy(inquiry).as(query().from(followup)
.where(followup.inquiry.eq(inquiry)
.orderBy(followup.id.desc())
.limit(1)))
I have requirement where I need to get the records based in join of three table with pagination(addition requirement are also there). So I have written a nativeQuery to get the records. Below is the sample query
#Query(value = "SELECT "
+ "a.GROUP_REF_ID as refId "
+ "count(case when c.STAT_CD in :userStatus then (c.grp_user_id) end) as numberOfUsers, "
+ "count(case when b.STAT_CD in :itemStatus then (b.grp_item_id) end) as numberOfItems "
+ "from grp a left join grp_item b on a.grp_id=b.grp_id left join grp_user c on a.grp_id=c.grp_id "
+ "where a.stat_cd in :status and a.co_id in :cids "
+ "group by a.GROUP_REF_ID,a.grp_nam,a.GRP_DESC,a.co_id,a.co_nam,a.CRTE_BY, "
+ "a.CRTE_DT,a.UPDT_BY,a.UPDT_DT ", countQuery = "select count(*) from grp where stat_cd in :status and co_id in :cids ", nativeQuery = true)
public Page<Object> findByStatusAndCompanyIdIn(#Param("status") String status, #Param("cids") List<Long> companyIds,
#Param("userStatus") List<GroupUserStatus> userStatus,
#Param("itemStatus") List<GroupItemStatus> itemStatus, Pageable pageable);
Now the requirement is also that these records are to be sorted on any of the column in select part. So, if user passes numberOfItems, the records are to be sorted on it. But I am facing an issue here because if I pass Sort parameter as numberOfItems, spring prepends an a. before numberOfItems which results in error that not able to find a.numberOfItems.
Is there a way I can stop spring from prepending table alias while creating a query with Sort, or should I write my logic in a different approach
Making my comment an answer so the question can be marked as answered:
Wrap the whole select in another one: select * from (<your current select>) x
I have solved the issue by creating a projection. (Kotlin was used but you’ll get the gist.)
class ShowRepository : JpaRepository<Int, Show> {
#Query("SELECT s AS show, (CASE WHEN (s.status = 'scheduled') THEN s.scheduledStartTime ELSE s.startTime END) AS time FROM Show s")
fun findShows(pageable: Pageable): Page<ShowWithTime>
}
interface ShowWithTime {
val show: Show,
val time: Date?
}
This allows Spring-Data to work its full magic, and using Sort.by(Order.desc("time")) works like a charm.
I’ve written it up with a little bit more detail here: Sorting by a Non-Entity Field.
I have problem with Fulltext Search (php,mySQLi)
With sql LIKE it works and no errors(not FULLtextSEARCH). But when i run it with MATCH it doesnt work and wamp returns Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\myweb1
....
include 'connect_db.php';
$result = mysqli_query($con, "SELECT * FROM $cat
WHERE title
LIKE '%YTE BLADE%'
OR description LIKE '%predam%'
OR locality LIKE '%predam%' "); //with this it works but its not FULLtext search
$result = mysqli_query($con, " SELECT * FROM $cat
WHERE
MATCH (title,description,locality)
AGAINST ('autobus' IN BOOLEAN MODE);");
while($row = mysqli_fetch_array($result)){....then i display data
Can you help?
I solve that. Problem was that muss be set in phpMyAdmin Storage Engine from InnoDB to MyISAM then it works.
Final Fulltext search code was:
$result = mysqli_query($con,"SELECT *,
MATCH(title, description, locality) AGAINST('$keyword') AS score
FROM $cat
WHERE MATCH(title, description, locality) AGAINST('$keyword')
ORDER BY score DESC, create_date DESC;");
Thanks
I am trying to write an SQL Query that will only order based on the time field of a date-time object in Oracle DB. Here is what I tried:
String getPricesQuery = "SELECT * FROM price WHERE SELECTIONID IN (SELECT ID" +
" FROM selection" +
" WHERE EVENTID =" + eventID + ") ORDER BY TIME(TIMEOFISSUE) ASC";
I read that the TIME() function can be used to extract the time portion of a Date-Time, but I imagine it makes it somewhat more complex, when trying to use it in an ORDER BY clause?
You can use :
ORDER BY to_char(TIMEOFISSUE, 'hh24miss')
ORDER BY TIMEOFISSUE ASC is enough or desc you can use.