I have a table like so: And I would like to return an entire row containing the uniqueID, scandatetime, and latest scanfacilityname (i.e., max scandatetime where scanfacilityname is not null). I have tried the following query: But im not sure if this is correct/if I need the coalesce. Answer You can use the m…
SQL Server – Calculating target vs actual values per week for sales overview
I am new to SQL. I am trying to create an over view using these 2 tables Actual sale Week_Year Target sale To combine into this resulting view with Targets and Actuals: where column Target is ‘Total to be sold’ spread linearly between the available weeks. How can I achieve this using SQL Server? A…
UPPER and LOWER functions in Informix DB LIKE queries do not work with all entries in the table
Background information: IBM Informix Dynamic Server Version 12.10.FC14WE DB_LOCALE=et_EE.utf8 Table has an ID primary key, no indexes Column datatype lvarchar (-1) The table column has names like “FIRST COMPANY”, “SECOND COMPANY”, “Third”. To find name matches the UPPER fun…
How to write this kind of query in Oracle
I have a MySQL database and I want to migrate all query to Oracle and since I am not an expert in Oracle SQL I am stuck here. I have query like this My question is: How to write this ORDER BY expression in Oracle SQL? Answer You can use There is no column naming format containing back ticks in
Invalid Number Exception in SQL when trying to call select statement from Java
I am trying to call a select query from my Java Program but i am getting Invalid Numbererror. I am trying to call the query something like this code I am getting query something like this: Result I am getting the error Invalid number in the line P.PACKAGE_ID = {0}. I gone through and come to know that if i
Can’t return column table when the table have just FK?
When I choose a table when it doesn’t have any Primary Key, my query returns nothing. So what’s the problem in this query? This is result when I have pkin my table: And this is result when I haven’t pkin my table: Here is the query: Answer As you are putting INNER JOIN with PRIMARY KEY const…
What are difference between KEEP and OVER in Oracle analytic SQL [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 2 years ago. Improve this ques…
Rails ActiveRecord – Order query by matching number
I have a model called Location. This table has 2 fields I want to order by: rating (integer) and name (string). I want to order alphabetically by name, but if the rating is 5, I want that rating to come first. If the rating is anything else except for 5, I want them to unbiasedly show up in alphabetical order
Find the record which have the greater value in top 2 month
I want to retrieve a record where the age group is greater than 50 and show the top 2 month. As we can see in the age_group there is 2 row fall in month ‘3’. The total value in month ‘3’ is 28. And the another month which have the greater value is month ‘4’ Answer You must group by
right way to get sum of all the counts done in sql
This is my query, I want to get how many numbers of phones call received today as one column, so how do I do a sum using count function? If I do a sum, that would just return the total sum? how do I return the total numbers of all calls received today, I would do count uniquecallerID and then