I have data represented in this fashion (not sure I properly call it an adjacency list, but that’s the best description I can think of): +——–+——-+ | Level | ID | +========+=======+ | …
SQL : Finding duplicates and flag in separate column with Case
I am trying to find duplicates in the table and wanted to add a new flag column. Sample data below : Column A Column B 1 888 1 999 1 777 2 …
Why selecting a single attribute returns less rows than selecting all columns in oracle SQL
The tables created and the queries made are not the primary focus of this question, what confuses me is that why the first query and the second query returns different numbers of rows I want to find the sid of the sailors who have not ordered all the red boats, the first query above returns the correct rows I…
Oracle SQL – Define the year element of a date dependent on the current month
I am trying to create a view in SQL Developer based on this statement: SELECT * FROM ORDERS WHERE START_DATE > ’01-JUL-2020′ The year element of the date needs to set to the year of the current date if the current month is between July and December otherwise it needs to be the previous year. Th…
Snowflake Unable to insert multiple rows using insert into having md5 field
I am adding multiple rows using INSERT INTO table VALUES as follows: insert into hub values (md5(md5(‘test1’)) as enc, CURRENT_TIMESTAMP() as ct, ‘DATA_SOURCE_1’, ‘test1’), (md5(md5(‘test2’)) as …
General question on optimising a database for a large query
I have a database that stores data from sensors in a factory. The DB contains about 1.6 million rows per sensor per day. I have the following index on the DB. CREATE INDEX sensor_name_time_stamp_index …
SQL compares the value of 2 columns and select the column with max value row-by-row
I have table something like: GROUP NAME Value_1 Value_2 1 ABC 0 0 1 DEF 4 4 50 XYZ 6 6 50 QWE 6 7 100 XYZ 26 2 100 QWE 26 2 What I would like to do is to groupby group and select the name with …
How select all data using HAVING clause in WHERE condition?
I have created a table which is keeps records of which product is sold by whom and how much each month; month total product cons_name 2020-01 10 xyz 123 2020-02 5 abc 456 2020-02 4 def 789 I was …
How do I combine dateadd and convert?
I have a query that shows the month (converted from date of day): DECLARE @Month varchar(6) = ‘202101’ SELECT [Month] = CONVERT(varchar(4), YEAR(Date)) + RIGHT(’00’ + CONVERT(varchar(2), MONTH(…
Can we create tables in PGADMIN4 without specifying the datatype’s length?
I am new to PostgresSQL and using pgadmin4 on my Windows machine, While creating tables came across datatypes like- char and char[] and also char Varying and char Varying[]. I want to know is there a …