What is the best way to search in a database for a request such as 'Hong Kong Jazz club' ?
The database has a table with the following fields :
- place name
- location (country, city, district)
- activity
Hong Kong will be found in the field 'location' and jazz club in the field 'activity'.
The issue is on how to analyze the text entered by the user 'Hong Kong Jazz club' and return relevant results.
Maybe it is too complicated to search this kind of thing in one field (and that's why Foursquare uses 2 fields, one for the activity and one for the location).
SET #input = 'hong kong jazz club';
SELECT *
FROM tablename
WHERE #input LIKE CONCAT('%', Location, '%')
AND #input LIKE CONCAT('%', Activity, '%');
SQL Fiddle link: http://sqlfiddle.com/#!2/11ffc/1
Related
my website takes a dataset and the dataset contains data about a students or employees..etc, so I want to display the column names to the user.
Is there a way to pull the fields name?
ex:
Name, Age, Country
String, Number, String
Fahad, 13, riyadh
Jane, 27, United Kingdom
Andrew, 29 , United States
Mary, 19 , France
I want to display "Name" "Age" "Country" to the user
I'm using node.js mongoose.
If your documents have similar structure, why not just
Object.keys(db.your_collection.findOne())
for more accurate u need use the lean() method because it will
POJO values else it will return mongodb instance keys instead of document keys.
Object.keys(db.your_collection.findOne().lean())
I have the following two Access tables
Employees
id Name
1 bob smith
2 james bird
3 jane big
Events
id emp_id Notes
1 1 fell down the stairs
2 3 paper cut in the break room
I also have the following Excel file that I would like to 'suck' (import) into the Events table. The problem is the data needs to be correlated on the name/emp_id field and I'm not sure the best way to do this.
Excel_sheet
Employee Name Notes
bob smith feel asleep while driving
The access table uses references to the Employees table, whereas the Excel sheet is using names. What are some options for me to bring this Excel sheet into Events table and convert the names (bob smith) into their associated id's from the Employees table?
Assuming names are consistently spelled in both datasets and only one person exists for each name, try:
INSERT INTO Events(emp_ID, Notes) SELECT ID, Notes FROM excel_sheet INNER JOIN Employees ON Employees.Name=excel_sheet.[Employee Name];
Build that SQL in a query object or run in VBA:
CurrentDb.Execute "INSERT INTO Events(emp_ID, Notes) " & _
"SELECT ID, Notes FROM excel_sheet " & _
"INNER JOIN Employees ON Employees.Name=excel_sheet.[Employee Name];"
Suggest you test with a copy of database.
Name is a reserved word and really should not use reserved words as names for anything.
I have the following table:
DEST_COUNTRY_NAME ORIGIN_COUNTRY_NAME count
United States Romania 15
United States Croatia 1
United States Ireland 344
Egypt United States 15
The table is represented as a Dataset.
scala> dataDS
res187: org.apache.spark.sql.Dataset[FlightData] = [DEST_COUNTRY_NAME: string, ORIGIN_COUNTRY_NAME: string ... 1 more field]
I want to sort the table based on count column and want to see only count column. I have done it but I am doing it in 2 steps
1- I first sort to get sorted DS - dataDS.sort(col("count").desc)
2- then select on that DS- (dataDS.sort(col("count").desc)).select(col("count")).show();
The above feels like am embedded sql query to me. In sql however, I can do the same query without using an embedded query
select * from flight_data_2015 ORDER BY count ASC
Is there a better way for me to both sort and select without creating a new Dataset?
There is nothing wrong
(dataDS.sort(col("count").desc)).select(col("count")).show();
It is the right thing to do and has no negative performance implications, other than intrinsic problems of sorting as such.
Use it freely and don't worry about it anymore.
I'm building an app where employees can be added to the database and each employee belongs to a particular company, which can be chosen from a select field on the form. The form to add employees also contains a salary field and I would like to be able to display the companies with their total salary expense (based on the sum of salaries of its employees).
At first, I imagined I would use a single "employees" collection. Then, for example, choose "Apple" as the company, and finally, in the end, I would end up with a list of employee objects where I can loop through all the employees where "Apple" was the company and sum all the salary fields. This ended up being a poor approach. Next, I decided to create a separate collection of "companies". Then, before saving an employee, I look up the company object ID, and save that as the company.
For instance,
{ firstName: "Bob", lastName, "Smith", company: "5b62a456e7179a07334478a5", salary: 7}
Where "5b62a456e7179a07334478a5" is the "_id" field of Apple.
How do I continue to define this relationship in MongoDB?
Do I add an employees field to each company and try to save each employee to a company upon saving them to the employee's collection? In this way, I can try to access the sum of all employees within each company to obtain a total salary expense.
But I would then have to write to two different collections each time a new employee is saved. Also, what would the flow of that even look like? I would need to use the company _id field to look up the company and then save the employee to the company. So, would I have to perform a query and two writes on each new employee save?
You can use the lookup feature to do a "join"
db.table1.aggregate([{
$lookup: {
from: "table2",
localField: "table2column",
foreignField: "table1key",
as: "alias"
},
{
$project:{
//columns you want
}
}
}])
That being said...if your data is relational and not obscenely huge, a relational database might be a better choice.
I have this excel sheet and I want to migrate it to Access (in the near future some other DB manager) And I don't know how to normalize it exactly, I know this might be very opinion base. Currently they use this table for inventory
This is the original Table (sheet)
"TableName: Parts", Fields:"Id_Part", "No_Part", "No_Mold", "No_Lot", "Rev", "Description", "Area", "No_Job", No_Batch,"OrderDate","RecivedDate"
Explanation of problem:
ok the idea is to create a DB that stores all the part numbers the "x" company has, these part numbers have the corresponding field:
1.- Id_Part : is the unique number for each part.
2.- No_Part: Number part of each part that the company uses for there products.
3.- No_Mold: Each Part Number uses a Molding Item, some part numbers use the same Molding Item.
4.- No_Lot: The Lot Number is to keep track of the part numbers in case the client has some issues with the final product. (Its like a tracking number).
5.- Rev: is for Revision control example: A, B or C.
6.- Description: Describes the part number.
7.- Area: name of the department in with the part number is used ( like a type of Part Number).
8.-No_Batch: Its similar to the Lot number, but its an internal number for the company.
9.- Order Date: Date in witch we ordered a part number form a provider.
10.- Received Date: Date when we get that part number from the provider.
This is how I tried to Normalize it
Table1 Name: Parts
Fields: Id_Part, No_Part, Id_Mold, Id_Lot, Id_Rev, Id_Description, Id_Area, Id_job,
Id_Batch, Date_Order, Date_Recived.
Table2 Name: Areas
Fields: Id_Area, Name
Table3: Molds
Fields: Id_Mold, No_Mold, Id_Part
Table4:Jobs
Fields: Id_Job, No_Job
Tablr5:Batchs
Fields: Id_Batch, No_Batch
Table6 Name: descriptions
Fields:Id_Description,Description,Id_Part
Table7 Name:Rev
Fields: Id_Rev,Rev,Id_Part
Any help is useful.
It seems like the PartRevision is the main table here rather than the part. You don't order a Honda Accord, you order a 2013 Honda Accord.
You purchase a PartRevision and it goes into a batch and a lot. You sell a part revision and it pulls from a batch and a lot. Here's how I'd set it up.