access select query between 2 date fields as criteria - ms-access-2010

Trying to figure out how to select records in Access where there are 3 fields: Manuf_Date, Date_Opened and Record ID. I want to find records where Date_Opened is 2 years greater than Manuf_Month_Year.
I entered this function as criteria in access under the Manuf_Month_Year field
<=DateAdd("yyyy",-2,[(dbo_TW_Parent_Child_All_Records.Date_Opened])
<=DateAdd("yyyy",-2,[(dbo_TW_Parent_Child_All_Records.Date_Opened])

Try with some syntax clean-up:
<=DateAdd("yyyy",-2,[dbo_TW_Parent_Child_All_Records].[Date_Opened])

Related

DynamoDB - Extract date and Query

I am having the following table in my DynamoDB.
I want to get/extract all the data using the following condition or filters
This Month data : This will be the set of records that belongs to 1st of this month to today. ( I think this I can achieve using the BEGINS_WITH filter , again not sure whether this is the correct approach )
This Quarter data : This will be the set of records that belongs to this quarter, basically from 1st of April 2021 to 30th June 2021
This Year data : This will be set of records that belongs to this entire year
Question : How I can filter/query the data using the date column from the above table to get these 3 types (Month , Quarter ,Year ) of data.
Other Details
Table Size : 25 GB
Item Count : 4,081,678
It looks like you have time-based access patterns (e.g. fetch by month, quarter, year, etc).
Because your sort key starts with a date, you can implement your access patterns using the between condition on your sort key. For example (in pseudo code):
Fetch User 1 data for this month
query where user_id = 1 and date between 2021-06-01 and 2021-06-30
Fetch User 1 data for this quarter
query where user_id = 1 and date between 2021-01-01 and 2021-03-31
Fetch User 1 data for this month
query where user_id = 1 and date between 2021-06-01 and 2021-06-30
If you need to fetch across all users, you could use the same approach using the scan operation. While scan is commonly considered wasteful/inefficient, it's a fine approach if you run this type of query infrequently.
However, if this is a common access pattern, you might want to consider re-organizing your data to make this operation more efficient.
As mentioned in the above answer by #Seth Geoghegan , the above table design is not correct, ideally you should think before placing your Partition Key and Sort Key, still for the people like me who already have such kind of scenarios, here is the steps which I followed to mitigate my issue.
Enabled DynamoDB Steams
Re-trigger the data so that they can pass through the DDB Streams ( I added one additional column updated_dttm to all of my records using one of the script )
Process the Streams record , in my case I broken down the date column above to three more columns , event_date , category , sub_category respectively and updated back to the original record using the Lambda
Then I was able to query my data using event_date column , I can also create index over event_date column and make my query/search more effective
Points to Consider
Cost for updating records so that they can go to DDB Streams
Cost of reprocessing the records
Cost for updating records back to DDB

Change "Date Added" Field based on values in another field

I'm just learning Microsoft Access, and I'm trying to write an update query that will change the field "Date Added" to a certain date based on another field called "Plant". Example: If Plant for a record = "MP", then change [Date Added] to 6/1/2013
The problem is that the values in the Plant field range from NULL to MP18, and the years need to match. I've looked at nested IIF statements, but I don't have any experience with SQL.
Create a new table along with Plant & the corresponding dates.
Link the tables via plant and write a query to update date
Main Table
Table with Criteria
Update Query
Update tblExample as a INNER JOIN tblChange as b ON a.plant = b.plant
set a.[date added]= b.[date added]
where years = 2018

sqlite table query - need help obtaining the correct results

I am writing an application using SQLITE.
One of the tables is users which includes the user_id and other field as name, email, etc. Another table is groups with a field group_id and other fields as group name.
users table
groups table
Then I created a table users_groups, specifying which users are part of which groups, in this table we have the user_id and the group_id.
users-groups table
I can easily make a SEARCH of the groups in which for example, user 4 is.
SELECT * FROM users_groups WHERE user_id = 4
The result would be groups 1, 2 and 6, which is correct.
What I haven't been able to do, is to make a query in which I get the groups in which a user is NOT part of. If I make the following query:
SELECT * FROM users_groups WHERE user_id <> 4
The results would be groups 1 and 3, which is not correct, since user 4 is actually part of group 1 as well.
I've been trying with JOIN, WHERE, HAVING, etc... without success!!
Any suggestions?
Thank you!
When a user is not member of a group, that group ID might not show up in the users_groups table at all, so you cannot use a simple SELECT on this table alone.
This query returns the user's group IDs:
SELECT group_id
FROM users_groups
WHERE user_id = 4;
This query returns all other groups:
SELECT group_id
FROM groups
WHERE group_id NOT IN (SELECT group_id
FROM users_groups
WHERE user_id = 4);

how to change query of view and add union itself in drupal 7

I have a table that have 2 types of data first type is '1' second type is '2'
and i want to get 3 records of both by union so, i want to know that how
to get 3 records of both type from one table at a time so it is possible by
union with itself so i want to add
union with my views content so , how to get query of view and alter it and
where i put this query in drupal 7 but i have no one module for this data.
so, please help me how to get records and change query
You can use Views extra handlers module to union SQL queries of two different views/displays. https://www.drupal.org/project/views_extra_handlers

How do I use two sql syntax keywords

I have a sqlite database with a column named 'name'.
The name column contains 30 rows.
5 are populated with data and 25 give a null value.
I am trying to get sqlite to return only populated rows AND then order by asc.
I thought it be as easy as
SELECT * FROM students
WHERE name IS NOT NULL AND ORDER BY name ASC.
But I was wrong.
Any idea's?
Thanks
SELECT * FROM students WHERE name IS NOT NULL ORDER BY name ASC.
omit the AND.

Resources