I have a large table: CREATE TABLE “orders” ( “id” serial NOT NULL, “person_id” int4, “created” int4, CONSTRAINT “orders_pkey” PRIMARY KEY (“id”) ); 90% of all requests are about orders from the …
COALESCE(FIELD, “DEFAULT VALUE”) not working for postgresql + rails
sql = “SELECT DISTINCT(p.*), concat(u.first_name,’ ‘,u.last_name) as fullname, concat(‘@’,u.username) as username, cover.file_path, cover.file_type, avatar.avatar_path FROM products p …
Month difference between two dates in sql server
Please refer the below examples and kindly let me know your ideas. Output = 3 expected output = 2.5 Since I have only 15 days in Nov, So I should get 0.5 for Nov Answer Try this OR
inflation calculation in MS SQL
I have the below requirement to fulfill. How to achieve this simplistically. There is an inflation rate table as below I need to first get And then get Answer I think the best way to do this on SQLserver is to use a common table expression with recursion. I’m not 100% sure because I can’t test it …
Count total days between current day (SQL)
i’m trying to count the total days between current date and a specific column called “DayConfirm” (datetime). I want to show the total days in a new column beside the rows with “DayChanged” So far i …
Displaying a delimited string for values that are not in the GROUP BY clause
When I have an SQL query with a GROUP BY clause, It is often very useful to see some of the un-grouped values for easier debugging. My question is, how can I select a string that will be composed of the un-grouped values. For example, in the following code: I would like to have a way to select a string
Count Number of Columns In Hive
I am looking for a way to count the number of columns in a table in Hive. I know the following code works in Microsoft SQL Server. Is there a Hive equivalent? SELECT COUNT(*), FROM …
t-sql string unique ID (Northwind database)
I’ve been trying to get this right for some time now with no use. I have a table in mssql database and I want to insert new row using stored procedure The problem is CustomerID field which contains unique string for each record (ALFKI, BERGS, BERGS, etc.) I want to make a stored procedure which will ins…
How to export all data from table to an insertable sql format?
I have a Table (call it A_table) in a database (call it A_db) in Microsoft SQL Server Management Studio, and there are 10 rows. I have another database (call it B_db), and it has a Table (call it B_table), which has the same column settings as A_table has. But the B_table is empty. What I want: Copy every row…
DB agnostic SQL for CURRENT_TIMESTAMP
I’m currently using Oracle, but most of the SQL is db agnostic. One exception is CURRENT_TIMESTAMP which fails in MSSQL. Is is possible to move to a more portable syntax for this too? Answer According to their documentation the following vendors support CURRENT_TIMESTAMP. Oracle Postgresql MySQL SQL Ser…