I am trying to split multiple columns of strings at the same time. My original data looks like: Table1 UserID Type ProductID 1 A, B 001, 003 and I want to end up with UserID Type ProductID 1 A 001 1 B 003 When I use I end up with this table that I do not want… UserID Type ProductID
Tag: sql
SQL where clause selecting specific data
In Microsoft SQL, I am trying to select a specific result from a table when available. Otherwise, other data should be retrieved. Giving the scenario tableA contains various fruits. I want to collect apples that are red otherwise, any other colors except for red should be retrieved. I am not sure which approa…
SQL: How to return revenue for specific year
I would like to show the revenue for a specific year for all customers regardless of whether or not they have revenue data for the specific year. (in cases they dont have data for the specific year, a filler like ‘no data’ would work) Sample Data looks like: Table 1 Customer Price Quantity Order D…
SQL how do I sum up a has many relationship
So I have the following table, I managed to join users and membership tables just fine with a left join however I’ve been unsuccessful at summing up the individual customers’ total. Here’s my code, the one-to-one associations seem to be doing fine however the summing up of the total seems to…
SQL to fetch value of one column such that a certain value in another column does not exist
I have the following Table t key value 1 a 1 b 1 c 2 a 2 c In the above table, the Key 1 has three values i.e. a, b and c. However Key 2 has only two values i.e. a and c. How to write a SQL that would return the Key that does NOT have the value
How to compare old value and new value in triggers and then mark as insert/update/delete in audit table
My Attempt: When I have inserted one record for ref_id into the table source_Det then in the audit table I am getting two records but ideally, it should check and load only that value which is newly inserted. Current Output: Expected Output: Basically, I need to check two columns ref_id and sys_other. If only…
How to select from two selected tables in Laravel Query Builder?
I want to convert my SQL to Laravel Query Builder version, however I can’t do that. Can anyone help me to solve this case or give me some advices, thank you. Original SQL that work fine in mysql server. Converted the original SQL to Laravel Query Builder, but it doesn’t work. Error: SQLSTATE[42S02…
Is there a (key:value) pair datatype that can be used as a column in SQL – Specifically Google Cloud Spanner?
Given the scenario that I would like to store sales of a store in a table in a database in Google Cloud Spanner. That table would (in addition to the sale ID as the primary key) have to store a list of product IDs sold, along with the quantity of each product sold. Ideally, this would be in the form
select a single field with applying filters in elasticsearch
I would like to select all the filename field values by ACCOUNT and APPLICATION_NAME Assuming as in SQL I need to do this : this is a screenshot of a log entry sample in the kibana interface Answer selecting the unique values of a specific field is exactly like running an aggregation query at one of the SQL d…
SQL Custom Function is not returning data as expected by matching to my conditions
I am trying to create this function but null values fail But some of the conditions are not working, specially when I am passing null calls that are not giving expected results are: Expecting above to return (‘REVIEWED’, -2) while I am getting nothing Expecting above to return ( , -2) while I am g…