This is my code SELECT * FROM `contacts` WHERE name = ‘a%’ AND name = ‘e%’; but I’m getting error so, how to display records in the table which is starting from a and e? This is my error:- #1064 – …
Tag: sql
Capture logging for stored procedure in Postgresql
We are working on a reporting project where we are executing stored procedures to perform transformations on the source data and convert it into the desired format. The transformed data will be inserted into a different table. We would like to know what are the best practices that needs to be implemented in t…
Python – Running a SQL in a loop based on column value
I am trying to build a SQL query that runs based on certain conditions (if a column is filled run Query 1 else Query 2 and so on) as shown below: I am trying to build something like the above but the number of fields as variable (fields like col_a and col_b) are 6 in number. Is there a way
parse string containing comma in csv using mysql? (or maybe pandas?)
(I’m using mysql v5.7) I have a csv file that has something like mytable1 note that ‘aaa,bbb,ccc’ is one string and ‘8,3,5’ is one string.. I know it’s not a good practice putting data like this but this is what I have given from other department… so my first task was…
Determining what index to create given a query?
Given a SQL query: How do you determine what index to write to improve the performance of the query? (Assuming every value to the right of the equal is calculated at runtime) Is there a built in command SQL command to suggest the proper index? To me, it gets confusing when there’s multiple JOINS that us…
MySQL (Percona) Error 1452: Cannot add or update a child row for no reason
I have 2 Database Tables “users” and “tasks”. The tasks table contains two foreign keys for the createdBy_user_id and updatedBy_user_id columns both referencing users.id. If I try to insert an entry to tasks (after making sure the user referenced by the foreign keys exists) like this: …
SQL Query calculating two additional columns
I have a table which gets populated daily with database size. I need to modify the query where I can calculate daily growth and weekly growth. Current Output I would like to add two additional columns which would be Daily Growth (DB_SIZE sysdate – DB_SIZE (sysdate -1)) Weekly Growth (DB_SIZE sysdate …
Selecting values from different columns in rows with the same ID
I have a table called COURSE_SELECT that shows students and which online products they will be able to access, but each product is in a different row, even when each of them has their own column. Table: COURSE_SELECT The vendor needs me to send a CSV file with only one row per student, like this: I have no id…
Compare values of timestamps and assign a value to each of them in case they have changed
DB-Fiddle Expected Result: In the above result I want to list all products from the table and compare the two time_stamps to each other. If the plan_week of one product has switched between the both time_stamps I want that in the additional column called week_switch the word yes gets inserted and if not the w…
Msg 100, Level 16, State 0, Line 109 insert statement error
While inserting the values in this table error occurred.and after adding constraints it’s not working on that condition too. What to do?? Answer When you have defined relationship then data should be present in Parent table first before inserting the data in child table otherwise data in child table is …