I have been trying to generate a series of dates (YYYY-MM-DD HH) from the first until the last date in a timestamp field. I’ve got the generate_series() I need, however running into an issue when trying to grab the start and end dates from a table. I have the following to give a rough idea: Postgres 9.3…
“No database selected” when implementing Zebra_pagination with SQL/PHP
Relatively new to PHP and first Stack question, so apologies in advance for any mistakes on my part. I’m trying to implement Zebra Pagination with my SQL database (using latest MAMP) and getting an error of ‘No database selected’. I think the issue lies in how I’m hooking up my connect…
REPLACE empty string
I discover some behavior I didn’t know before. Why this line of code does not work? I can’t even have ” in where condition. It just doesn’t work. I have this from imported Excel where in some cells are no values but I’m not able to remove them unless I used LEN(”) = 0 funct…
Different results for TO_TIMESTAMP_TZ and CAST AS TIMESTAMP WITH LOCAL TIME ZONE in Oracle DB
I have an Oracle 11g database and I’m trying to experiment with how DST is handled with TIMESTAMP datatypes (especially ones created from incoming data that doesn’t have a time zone included). I’m …
MYSQL: UNION results between two tables where omitting records from first table if PK found in second table
I have two tables products and product_edits which hold product information on the pricelist. My app works in a way that if user changes any product info in products table it inserts it into …
Calculates the difference between employee salary and the average salary of job group
Given a table like: How to write a query that for each employee calculates the difference between his/her salary to the average salary of his/her job group? To get the avg. Salary for each group I use: But I’m struggling to find the difference between salary and avg. salary for each job title. Answer De…
How to subtract years from sysdate
What would be the expression to check if someone’s 20 years or over without hard-coding the date? In the SQL SELECT student_fname FROM students WHERE dob<'05-MAR-1995'; I was thinking about …
Run a query with a LIMIT/OFFSET and also get the total number of rows
For pagination purposes, I need a run a query with the LIMIT and OFFSET clauses. But I also need a count of the number of rows that would be returned by that query without the LIMIT and OFFSET clauses. I want to run: And: At the same time. Is there a way to do that, particularly a way that lets
Sharing composite foreign key based on the same columns across multiple tables in MS SQL Server
I have database with multiple tables which contains information about different instruments (Currencies, Funds, Equities etc.). All instruments have Type and Id fields which represents unique key for …
Query to check if a certain row has 2 words
How to return rows where a column has 2 words (that is, strings separated by a space) in it? It must be purely using SQL. Answer I dont know the names when querying. Its a big dataset. I only have to check if the name contains a spacebar basically (from a comment). If you want to distinguish names that have