Skip to content

Tag: mysql

Cannot use Count(*) in Lag()

I have a simple query but it keeps throwing “Invalid use of group function”. It works fine when I remove “count(*)”. How can I get the count without using it in lag? Answer Hmmm . . . MySQL should allow the use of aggregation functions with window functions. Maybe there is a bug in the…

MySQL get previous day data

I have the following table What I try to get is writing the day before data on the following day I can get yesterday but don’t know how to do it for all rows. Thanks, Answer You can use next approach. In this query we use join same table to itself by date with 1 day shift. DB Fiddle

Need Help Converting a SQL Query to JPQL

So far, Spring’s JPA repositories have sufficed for me, but now I need a custom query. I have struggled with this for a day trying to learn more about SQL, joins, etc and came up with a native MySQL …

SQL Join ON clause valid referencing on aliases

I am generating an SQL query and I need to get the data from a JSON stored on a field of my table. It goes something like this So basically I am trying to get put a connection with tables creation and lookup_detail through field FACILITY_DATA which has JSON data and alias of loanType to reference against DETA…