I need to set a CHECK constraint on a column based on the value in other column (both within the same table) Like when COLUMN A is NULL, COLUMN B should be NULL But if COLUMN A has values 1 or 2 or 3 then COLUMN B should definitely have a date value. Answer Define B as a date. And
Tag: sql
fetch the data from array of objects sql BigQuery
I need to fetch key value pairs from the second object in array. Also, need to create new columns with the fetched data. I am only interested in the second object, some arrays have 3 objects, some have 4 etc. The data looks like this: The desired output: Answer Below is for BigQuery Standard SQL if applied to…
How to unnest the table based on date interval in Presto?
I have a table with events, where start_dt is a start and end_dt an end of the event. This table is partitioned by dt column derived from the end_dt. This means that events that start before and end after midnight are present only in one partition. What I need to do is to split each event into as many rows
Microsoft Access 2016 – Need to combine SQL query using JOIN …. ON Col1 MOST LIKE Col2
I am working in Microsoft Access 2016. I have a data table [Data] that contains many thousand rows of data. I have a lookup table [Lookup] that contains all of the project IDs that are known. These tables should combine on the project ID, which is a string field. Normally, I would join these tables using: The…
Select how many documents are in other table for each person
I have 3 tables. Client,Documents and ClientDocuments. The first one is the clients,where the information for each client are. The second one is the documents, which document can go in the system. The third one is the ClientDocuments, which client has which document. Tables Here I have to do a select where i …
Incorrect datetime value in MySQL table
I have just created a new MySQL in an AWS Ubuntu instance. Then I have copied a table from another MySQL server to the new created database. This is the structure from some fields from one of the tables: My issue is that every time I try to enter a new record on the table, there is an error at
Group by portion of field
I have a field in a PostgreSQL table, name, with this format: JOHN^DOE BILLY^SMITH FIRL^GREGOIRE NOEL^JOHN and so on. The format is LASTNAME^FIRSTNAME. The table has ID, name, birthdate and sex …
Oracle SQL count same field across multiple tables
I have an oracle database that has the same name field in multiple tables. It kind of looks like this: The common field in each table can either be ‘yes’, ‘no’, or null. I’m trying to get the value counts of all the fields in one query, but I can’t figure it out. Basically …
Using rank to enumerate the session
Hi can anyone help me for this. What im trying to do is to rank my session id but it seems not to work as it returns me just “1”. The third row should be 2, the row 5 should have 2 for rank and the row 6 should have 3 for rank and so on. I try to enumerate
How do I select just mutual rows in SQL?
I have a table with a source_id and destination_id and a message and I want to group messages together. There can only be one message between a given source_id and destination_id, but I only want rows that have a mutual response for a given ID (say id 1). In the following examples, I want rows #1, #2, #4 and …