For my Smart home Stuff I create a Database, but I make a mistake during programming: the application posting stuff into the Database twice. I want to delete all rows, which contain duplicates. With …
Tag: sql
Get Data from a single table to an empty table
I am quite new to SQL. I couldn’t find solution and I want your expertise here. I have one table “boxes” and contains the color and type and condition. I want to get the number of types per color …
find total unique number of hackers who made at least one submission every day and find the hacker_id who made maximum number of submissions each day
Find total number of unique hackers who made at least submission each day (starting on the first day of the contest), and find the hacker_id and name of the hacker who made maximum number of submissions each day. If more than one such hacker has a maximum number of submissions, print the lowest hacker_id. The…
How to include a variable in a block WITH..AS?
I have this query to retrieve for each employee, his main and secondary function: Output : I want to integrate my previous query in the source query of my dimension : My expected output will be (for employee having EmployeeId=1) : Answer When you say: How to include a variable in a block are you asking how ca…
Compare values from one table with average calculation of value with same properties in other table
First post here… I’m trying to create select values from tableA in last 5 minutes and to compare those values each row by row with average(value) from another table. For example: tableA id | …
Combine and fuse the results of two SQL queries with UNION
I am writing two seperate SQL queries to get data for two different dates like so: SELECT number, sum(sales) as sales, sum(discount) sa discount, sum(margin) as margin FROM table_a WHERE day = ‘2019-…
Join two sys.columns tables from different servers
I have two similar dbs on two different servers. I’m trying to join their sys.columns tables, but I don’t understand why this wouldn’t work SELECT * FROM server1.db1.sys.columns t …
How to order by rows according to multiple columns
I have this table list of records to be sorted. where MAIN_NAME is the father’s name, STUDENT_NAME is their son/daughter’s name. Null value if the record is the father itself, and IDENTIFIER wherein …
Find max value from coalesce function
This is my query: declare @t table (date1 date,date2 date,date3 date) insert into @t values (‘2019-01-01′,’2019-01-20′,’2019-02-10′) insert into @t values (null,null,’2019-02-01’) insert into @t …
How do i update multiple records using MERGE statement and use max(column_value) based on previously updated records in the same statement?
I need to use the Oracle MERGE statement to update records of the table. One of the column I would like to update should be derived from MAX value of both existing records of the table and the records …