I want to join county and county_type tables and get only those county that doesnt have a type =30. From below example id = 1 and 3 should only be the expected output county output: Tried this: what i am getting is cumulative: Answer You want not exists:
How to union all, but separate the columns in mySQL
The first query returns the data for the last 7 days, and returns 90 in total, while the second query returns data for the previous 7 days, returns 55 in total. Current output is: But the output should be: Answer You can use conditional aggregation:
How to get the time difference of first occurrence of a record with another record
We have a monitoring system that posts data to our postgres database in this format: Our goal is to calculate the time between wa-event-triggered events and wa-event-recovered events, if i have data that looks like this, my query below works just fine. This gives me this table which is great! However the data…
How to save date in SQLite flutter database?
I am making an app in which users can fill a form and can save their financial transaction details for every transaction they make, for this, I want to add a date as well and also I want to fetch data using the date as well. I am creating my database as follows: I am mapping as follows: I have
SQL Server 2019: Cannot combine two queries, when 1 parses string
There are two tables (table1 and table2). Table 2 has a column called TaskDescription which has a string with several ‘tags’ embedded in it. I cannot change how that data is stored, as it comes from a a third party. I am able to pull out the taskID I want to grab all of the information from table …
How can I conditional join two tables to get results based on an evaluation (SQL Server)?
I have two tables in my database: Offices Positions How can I select all entries from Positions based on their Department and Section, but one above their level? I’m guessing I need a join with some kind of condition that gets evaluated to do this. For example, the Senior Dev position is at level 1. So,…
Get the number of the weekday from each date in a date list
DB-Fiddle Expected Results: I want go get the number of the weekday for each date in the table dates. Therefore, I tried to go with the solution from this question but could not make it work: How do I need to modify the query to get the expected result? Answer Get rid of the date keyword it is only needed
Email address lookup in SQL Server
We have a large subscriber database and have a lookup based on email address of type nvarchar(100). It sometimes times out probably because of a large scan of it. I want to improve this, but weary of some of the options. Would an index on it be ok, I can handle the additional storage if needed, or a computed …
SQL subtracting 2 subqueries
Fairly new to SQL and I wanted to see if I could get some help with subtraction. I want to subtract studentstaken – studentsnotreviewed and then as assign the alias total to the operation. I was thinking something along the lines of But getting some syntax problems I’m not too sure about. [Sample …
Create a string from inserted.id via trigger
I’m creating a trigger on insert that will create a new record in another table using the id from the newly inserted row. I need to format the id before I insert it into the other table. This is my …