This is a list name of tables stored a database MySql version 8.0.17 The table name storage policy is Table_ Western alphabet letter (issued by an algorithm that recognizes the connected user, privileges, etc.)_ Random number_ Month Number_ Current Year I need find on the database MySql all the table for firs…
Convert foreign key constraint from SQL Server to Oracle
I want to convert the following script(SQL SERVER) to Oracle: I have tried to run the same script in Oracle: and I got this error: I believe that the “WITH CHECK ADD” is the problem! Answer See if this helps. A master table – its primary key column will be referenced from the tdistribucion t…
Conditional annotations with Aggregation over only some fields in Django
So lets assume i have two databases in my Django project There exist multiple Price entries per day for the same article. Now I want to annotate an article queryset with the average price of every article on the previous day. But I have no idea on how to do this in one efficient query. What I have done is
Creating date segments in redshift SQL
I’m trying to create segments of date based on a flag. Below is the table I currently have order by start_date,end_date. ID start_date end_date flag 9659 5/18/2012 5/18/2012 0 9659 5/18/2012 5/18/2012 0 9659 6/8/2012 6/8/2012 0 9659 6/8/2012 6/8/2012 0 9659 8/25/2012 8/25/2012 1 9659 8/27/2012 8/27/2012…
Return column name of max value in a row SQL Server
Initial Table: Output Table: I need to get the Job Name (column name) of the row with the max value in SQL Server. Is there a way other than else if to do this because ‘greatest’ function is not available in SQL? (Coz I have 50 Jobs at least) Answer You can use apply and window functions: That sai…
Difference between performing INSERT INTO vs Using MERGE INTO
I started working on a project that already has some scripts running and while I was looking some of the scripts that have already been done I encountered an scenario that looks something like this. My Question here is why they would use the merge into and force the mismatch just to perform an insert, they co…
count and sum in case statement
What is the difference below if I use case instead of sum? I believe I would get the same output? Thanks! Answer The three are equivalent. All of them count the number of rows that meet the particular condition (salary > 100000). All return 0/1 and would not return NULL values for the column. From a perfor…
shopping cart with PHP and connected to the MySQL
Good evening, I am currently working on the implementation of a shopping cart through PHP and MySQL, I am getting the following error at line 172 onwards, I have been looking at the quotes but I cannot find the problem, what could be the solution to this? I have been changing this cart from a mysqli version o…
SQL query to fetch distinct values from same table
Let’s say I have this table: employeetable: empid joindate location HRupdatedate Changes 1 2002-01-05 Delhi 2021-03-01 New 2 2009-09-09 Mumbai 2021-03-05 New 1 2010-06-27 Hyderabad 2021-03-03 Transfer 2 2015-11-02 Delhi 2021-03-06 Transfer 3 2020-01-01 Mumbai 2021-03-06 New 4 2007-07-30 Delhi 2021-03-04…
Join two tables bring mismatch values MYSQL
I have two tables with >4million records i need to make a select query with where two columns match bring both tables value on this match and then i will insert that into a 3rth table: This is table A: (bitfinex) This is table B: (Kraken) I need to do a SELECT where timestamp and exchange_pair matches, as …