I have two tables, one for all the foods which contains food id, default name and other foods values. Another table is for the food name translations which contains food id, language id, translation. What i want to do is join between these tables by the food id to get the translation for food id = 5 for examp…
Tag: sql
Writing a Single Query w/ Multiple CTE Subqueries SQL/R
I have some data I would like to pull from a database, I’m using RStudio for my query. What I intend to do is write: The first CTE statement to pull all my necessary information. The second CTE statement will add two new columns for two row numbers, which are partitioned by different groups. Two additio…
TSQL – Union records based on partial uniqueness
Sample Data Currently inserted data: Goal: To insert record into the table variable (or cte/temp table) based on uniqueness ONLY ON [Id] field. “UNION” would not do that because, at minimum, [Group] is going to make duplicate records based on just [Id]… unique. Oh, and [Group] value basicall…
Use COPY to read a csv into database, while adding constant columns
I have a series of CSV files, in the format: “Alice”,”Bob”,”A”,123.46,”4″ “Charlie”,”Dana”,”B”,987.6543,”9″ … I want to produce a table like this: id file_id mch c1 c2 c3 c4 …
Flag the date when they return
Story: For each id , they have a join date to a subscription and when they get rebilled monthly, they have a returning date. The first part of the exercise was to flag consecutive months of returned dates from the join date. Here’s an example: Objective: What I would like to add is to flag those who ret…
MySQL select complete last month
How to select all data from last month (or 30 days)? I already found some answers, and mostly gives this solution But this gives me also the dates from the future I am only interested in the days from last month or 30 days (not next month and beyond) Answer Is this what you want? I added a condition so
Error :Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library
I’m trying to fetch data from MS SQL server in a shiny app. I’m using the odbc package version 1.2.2. When I run the app locally I am able to fetch the data and everything is fine. But on the server I have the following error : The following is a short version of my app. and the server :
max, over partition by, oracle, take max rownum record
I am trying to pull the maximum rownum in a partition. I am getting the below error message, so I need help to fix my SQL Query. I added in a row number and a row number in a partition in my SQL query. Code is below. I want to take the maximum over this partition and have tried changing
Query to find value in column dependent on a different column in table being the minimum date
I have a dataset that looks like this. I would like to pull a distinct id, the minimum date and value on the minimum date. This code will pull the id and the minimum date How can I get the value on the minimum date so the output of my query looks like this? Answer Use distinct on: This can
SET .. WHERE .. within batch throwing an error in SSMS v18.4
I am revisiting MS SQL after a few years, so apologies for a basic question! I am performing some address data cleansing, to expand abbreviations like DR into ‘DRIVE’ RD into ‘ROAD’ etc to help with identifying duplicate addresses. I am exploring ways to optimise my query by taking my …