I am quite new to SQL. I have a MS SQL DB where I would like to fetch the top 3 rows with datetime above a specific input PLUS get all the rows where the datetime value is equal to the last row of …
Tag: sql
columnA like %columnB
I’m trying to do select * where column1 = % column2 %. this is my query The error: The data types varchar and text are incompatible in the add operator. Answer You can cast the text to a varchar(max): Or, if b.Client is a text too: Notes (most of which already were commented): text is deprecated; you wa…
format date in oracle SQL
I was trying to learn how to format date in oracle pl oracle, when I ran below query its returns error Answer for my scenario I had to use to_char which perfectly solve the formatting issue.
Java + Postgresql : How to store Parent and List of all children in a HashMap>
I have an sql table Children : | ParentName | ChildrenName | ——————————————————————————— | parent 1 | child 1 | | parent 1 | child 2 | | parent 2 | child 3 | | parent 1 | …
Loop and insert more than one comma separated List in SQL
I wish to loop through two comma-separated values and perform an insert As an example lets consider two variables Using this loop I am able to extract @Answers and can perform insert. But I wish to extract @Qid and insert inside the loop. edit for more clarity it is a feedback module. my result table have Qid…
Sum By Criteria in specific column
I have questions about SQL Server query for SUM. I have 2 tables: 1) EmployeesAtt (EId, EName, Stats) -> I have some criteria for Stats (0 = late, 1 = overtime, 2 = normal) 2) AttLogs (ID, EId, late, overtime, normal) From EmployeesAtt table, I want to SUM the EId And Stats in dedicated column in AttLogs l…
changing sql statement to eloquent query
So I have an SQL statement as such; How do I change this to an eloquent query? Or is it better to just use a db:raw query? All inputs are very much appreciated. Cheers! Answer You can try this : Read more at whereBetween section in here
SQL Count In Range
How could I count data in range which could be configured Something like this, Table ZONE_CFG is configurable, so I could not use static value for this The DATE column mean maximum date for each ZONE And the result what I expected : Please could someone help me with this Answer You can use LAG and group by as…
What am I doing wrong in this where statement?
I’m using the following logic in my where statement. If I do just the statement below then it returns results However if I expand on the where logic to the following statement it returns no results. Why? Shouldn’t it return the same thing as where statement above? Basically what I want is the foll…
Roll up multiple rows into one postgresql
There is a role table How do I get the output as using SQL query : Answer Please try below query for your problem and let me know if still you are facing any issue.