I am trying to query a SQL view to show the transactions for the last business day (i.e. the day before, or the Friday if the day the query is ran is Monday). My query looks like this: I get the following error when I try to run this query: Msg 257, Level 16, State 3, Server PMICDB01A, Procedure ,
Tag: sql
How to force Rails ActiveRecord to use CamelCase in queries, instead of snake_case
I am trying to create a rails app that will connect to a production SQLServer that is used by 3rd party software, so migrating the database is not an option. I am able to connect to the SQL server without any issues (I used this guide for connecting to existing database, and this one to connect rails to SQL S…
Query that returns maximum and corresponding FK(ID) group by year which comes from another select that has averages group by FK(ID) and year
I have a raw table which contains the id (pk AI), farm_fk (or HERD), birthdate, nm (some indicator). I want to get the maximum of nm averages for each existing year and corresponding farm_fk. What is DID? 1st from table I got the averages of nm for each farm_fk group by year which returns some thing like this…
INSERT ON CONFLICT DO UPDATE using pg-promise helpers for multi row insert/update
I am trying to insert multiple rows to pgsql database using pg-promise. In my case, few records, which I am trying to insert, may exist already in the table. In such case, I need to update them. By …
(Laravel) Multiple counts, group by on same table with one query
I have two tables. I would like to get the values of the counts of these two rows (attacker, victim) from the first table and their respective userid from the second table, if possible. Table1: Table2: So far I only managed to get the values of the counts of rows attacker and victim but I achieved it using tw…
How to use JPA to save datetime of SQL to fix: “Conversion failed when converting date and/or time from character string.”
I got a very frustrated problem.. I cannot use the JPA save function to store correct datetime object of SQL, I got the following error: There is my code: In Controller: In Entity: Many thanks!! Answer I recomend you to use LocalDateTime of modern java.time. JPA automatically convert LocalDateTime into databa…
How to set flag to true and also get the total while grouping
Table Output as Thank you in Advance Answer Use conditional aggregation: You can also express the condition as:
How to deal with semantic version data type in BigQuery
I know that there is no data type in BigQuery. What would you prefer to deal with semantic versions in BigQuery? I have the following schema: software_version column is string but the data I store there is in semver format: `MAJOR.MINOR.PATCH-prerelease I especially want to perform operators < > =. This…
How to do select insert into statements and handling time series data and foreign keys?
I am completely lost on how to approach the problem I am having. I am trying to generate a boolean statement from one table and insert it into another table’s column. I am able to generate the boolean statement and create a new column as shown with the code and output below: This is what I have so far: …
SQL – WHERE NOT EXISTS [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I have a table with employees ID NAME SALARY and I am getting the employee with the most sala…