[Edit] : this answer helped DELETE FROM Table WHERE ‘RANK’ > 1 I have a table which keeps track of some entity’s status history (tb_status) DDL here is an example status_id ref_entity_aa ref_entity_ab status 1 “a” 1 OK 1 “a” 2 OK 1 “b” 1 OK 1 “b&#…
Tag: sql
Implement database schema for organizing historical stock data
I am new to MySQL, I try to use MySQL to store my stock data. I followed the answer by boe100 in reference: Database schema for organizing historical stock data I create my table as follows: mysql> describe StockDailyQuotations; Field Type Null Key Default Extra ts_code varchar(9) NO PRI NULL trade_date in…
PIVOT (without aggregation?) in SQL
I am trying to put together a select statement on some data like the below using TSQL: Table1: Property Detail Record No Surname Smith 1 First Name Anne 1 Title Mrs 1 Gender F 1 Surname Jones 2 First Name Ben 2 Title Mr 2 Gender M 2 Which I am hoping to get results which would appear like this:
SQL: Temp tables and script failing on second use, but works on the first
I have a script that makes use of temp tables. When I disconnect from the server, connect, and run the script, it works as expected. If I run the same script twice, it works the first time, and then on the second time, complains that; Column name or number of supplied values does not match table definition. I…
How to get employee name with minimum and maximum of salary for second employee name with same salary value in mysql?
I’m having a table odd_empcop in which minimum salary = 2000 and maximum salary =8000 , there are many employees having maximum salary of 8000. I want to get the employee name with minimum salary and maximum salary of second employee. I’ve applied this code: getting output like: But I want to get …
SQL many-to-one join – how to get blank fields instead of duplicated values
I have 3 tables: When I join this tables by ticket_id and query, i get result like this: But I want to blank duplicated values and get result like this: Is it possible to get result set like this? I’m working in AWS Athena(Presto SQL), but I would really appreciate your ideas/suggestions on this regardl…
Unfold Data by Column
I have a dataset that looks like this (where the codes of ID1 and ID2 can never be the same. So putting them together they are still unique): ID ID1 Name AGE ID2 Primary Secondary 1 1234 Jim 34 1111 Mars A 2 1234 Tom 24 1111 Mars A 3 1234 Rick 55 1112 Mars B 4 2222 Ann 22
How to insert an array value to an existing JSON document?
Given a column containing a JSON document, I can use JSON_SET() to set a key in the JSON document to a value. Supported values are null, true, false, numbers and strings; but I can’t figure out how to set an array. The example in the documentation (for JSON_INSERT(), but it works the same) weirdly shows…
Integrity constraint violation: 1052
Integrity constraint violation: 1052 Column ‘id’ in where clause is ambiguous (SQL: select * from kumeti_member_registrations left join members list on members list.id = kumeti_member registrations.member_name where id = 2)”, this Query please solve the error Answer Try this:
SQL only show orders with one order row. if more rows don display anything
i´m trying to search for orders with one specific article on the order row, but if there more than one row i don´t want to see any of the rows. This is a sample of two orders where i only want to get one resault. order 9891026 has two rows and 9891025 only have one row. result order_no line_no 9891026