I’m trying to display staff from the same department who earn more than their managers. SELECT ID, NAME, DEPARTMENT, SALARY, JOB FROM STAFF WHERE SALARY > ANY (SELECT SALARY FROM STAFF WHERE JOB = ‘…
Using SUM and CASE in Oracle SQL
I framed a query to get the counts grouped by a date column from 2 tables. select count(*),TO_CHAR(CREATION_DATE,’DD/Mon/YY HH’) as Date_TIME,’Table_1′ as TABLE_NAME from TABLE 1 where CREATION_DATE &…
Creating a query containing a SUM() of MAX() values with conditions
I have two tables: Meter (condensed) id Meter_Id Date Time Consumption 1 1 2016-01-01 0.5 0.0769 2 1 2016-01-01 1.0 0.0649 3 1 2016-01-01 1.5 0.0379 4 …
SQL left join with 2 or more count group
My table ID catone cattwo 100 2 1 100 3 1 200 1 2 expect result (count not sum) ID totalcat1 totalcat2 100 2 2 200 1 1 My …
Fiscal year and fiscal quarter
I have a table where I store order dates YYYY-MM_DD. How do I create fiscal year and fiscal quarter with the following requirements: Fiscal years: start date for Fiscal_Year_2000 is 1999-07-01 and …
SQL Data cleaning
I have a data set where I am trying to clean data. I want to remove the ** from email-address and phone_number and have just numbers in the phone_number column. how can i do it. Answer Here is one option using string functions: This removes ‘**’ from email, and all non-digit characters from phone_…
Calculating minutes between two timestamps in a pivot table
I have a SQL query that makes a pivot table showing the timestamps of various temperature points being collected. I need to add columns to show the difference between point 1 (126) and point 2 (120) …
SQl Query to get an output that resembles the image [closed]
I would like to get output the way its shown in the image attached and the way the input is organized is also shown in the image attached. Thanks!
SQL one-to-many relationship: Should I see a “many” field in the table?
This is something basic which drives me crazy: If for example I have a table “team” and a table “player”. And the team can have multiple players in a one-to-many relation. Should …
Chat schema with one side deletion
I’m struggling with a chat schema that permits deletion from one side of the conversation in a relational database (PostgreSQL). Here is my best approach: my schema All schemas I found were about …