My Table : CREATE TABLE `tbdata` ( `ID` INT(10) NOT NULL AUTO_INCREMENT, `PatientID` INT(10) NOT NULL, `RecordDate` DATETIME NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=INNODB AUTO_INCREMENT=1 …
Use another column as default value in migration
I am trying to add a new column to existing tableName table which has a column anotherColumn. exports.up = function (knex, Promise) { return knex.schema.table(‘tableName’, table => { …
CASE expression in WHERE clause for diferent and
Can I use case expression to build where like this? I need change where clause depending on the value of x variable. Answer An alternative to using OR is to use nested CASE statements: or you could simplify it to: However, you should check whether Oracle can use column indexes or if a separate function-based …
Transform table to smoothen records in one column
the situation (a real life situation) is: I have a table with “log” records, for simplicity let’s assume there are only columns NAME, TIME, STATE (in reality there are few more). There are cca 1 Milion rows in which there are 100 Names (computers) and cca 10 states (productive, idle, automat…
How to create all possible combinations with splitted items in SQL?
I have data as in below delimited format expected output – is the combination with each element and the element itself I am trying by splitting the data into different items as below any idea how we can create combination with splitted items? Thanks! Answer You have a couple of mistakes in your SQL. @da…
Will remove MySQL logs file impact the performance of the database?
One of our users is using Cloud SQL(MySQL). They turn on general logs flag and log_output is file. They need these general logs because of some special circumstances. MySQL generates about 8TB of general logs and these logs result a bigger use of the disk. Here is the tricky part: They want to remove these ge…
SQL Extract Values from Timestamp Difference
I’m trying to extract Days, Hours, Minutes, Seconds from the output of subtracting two timestamps in an Oracle database. I then want to take the extracted values and put them into separate columns. I …
Convert different dates in date column to rows in SQL Server
I want to display different dates as columns from LOGDATE column. Here are the details My query: This query returns this result: Expected output format: I have multiple types of SERVICE_TYPE and SERVICE_NAME, not just the three sown in the sample. How can I get my expected output? Any help would be appreciate…
SQL query to count rows grouped by an ID, but limit count on each group
So I have a bit of an unusual request. I’m working with a table with billions of rows. The table has a column ‘id’ which is not unique, and has a column ‘data’ What I want to do is run a count on …
Impala: count(distinct) with multiple where statement criteria?
I have a health outcome database where I’d like to be able to query counts of subjects that meet a specific diagnosis string within a certain date range. Dummy data (my_table) would look like this (…