I have input column name Ahar Aris Suchi Doll Dipti I want the output to be with two columns FirstLetter TotalsWordsWithThatLetter A Ahar, Aris S Suchi D Doll,Dipti I know recursive CTE/stuff …
Calculate time difference in days:hours:min:sec format
I have this query: Wherein I have to calculate the time difference in Days:Hours:min:sec format Output: My question is, how to calculate the sum of the 2 rows? My desired output is: Answer Find the difference in second & do aggregation :
Can’t add row in sql server because of date
I have a web application where I need to insert data in my SQL Server table, the problem is that I have this error in my Apache log: General error: 241 Conversion failed when converting date and/or time from character string. I have the same error when I try directly inside ms sql server. There is my php code…
Recreating relation between two tables
I have a 1:1 relation between data that was not an explicit foreign key in the database. E.g. Table 1 has a once, b twice and c once Table 2 also has a once, b twice and c once I want to create a foreign key from Table 1 to Table 2 when the value is the same: Expected Table
SQL and Oracle query to extract every thing before last two periods
I need to extract every thing before last two periods eg. Input: AA.BBB.12.11.cc Output: AA.BBB.12 Following is the sample query I am using but that returns only the characters before first period, but that is not I needed. Answer I would use REGEXP_REPLACE here: The regex pattern .[^.]+.[^.]+$ will match sta…
Select all orders except the max order for each distinct customer
Sorry for the poor formatting but as part of a larger problem, I have created a query that produces this table: How would I extract the rows that don’t have the highest id2 for each id1. What I want: I can only seem to figure out how to get rid of the max id2 overall but not for each distinct
SQL statement – get 1st minimum then 2nd minimum from join
sorry for terrible description but I have struggled to word this My 2 tables are like this tblParent.. OrderID Customer 789 Bob tblChild OrderID SortOrder Price 789 1 20.00 …
PostgreSQL alter column type from DATERANGE to TSTZRANGE and migrate the data
We’re changing a column run_dates (per request) from daterange to tstzrange, a column with a few months of test data. Essentially we want to migrate! I’m running the script below, inspired by postgreSQL alter column data type to timestamp without time zone and I have to admit, my SQL background is…
How to write a SQL query to find number of accounts tied to a particular value?
I want to find the number of companies tied to a specific membership field. This is somewhat complex, as many different companies can belong to the same membership number. Companies are identified by a 6 character string (account number), but in this table they can be either 6 or 8 characters long. I am only …
converting datetime field to date in sql query in laravel contorller
i have to execute an sql query into laravel controller the query inclueds where caluse in which it compares a field from database which is in datetime type with another field that i get from the blade which has a date type, so i have to convert the database field from datetime type to date type this is my que…