I run a gym and am trying to query my database to find out how many customers who signed up to the intro class also signed up to the next level class. For starters I am issuing a simple SQL command as follows:
Select * from 'classes' where 'name' = '4 Week Intro Class'
This comes back with zero matches because I assume there is no match due to the name of the class also contains dates and times. I want to only match on the partial class name not the whole name. I've tried = and LIKE and MATCH to no avail.
Once I get this result then I want to expand it further to show me all the customers who took this class also took the next level class name. Baby steps.
I can provide more info if needed. I'm using MySQL btw.
Thanks.
Ed
For your first query, there are no matches because you are comparing two strings, and they are not equal. Presumably, you intend:
Select *
from classes
where name = '4 Week Intro Class';
Only use single quotes for string and date constants.
You can use like by doing:
Select *
from classes
where name like '%Intro%';
When you ask another question, include sample data and desired results, as well as your attempt to answer the question.
Related
I have homework from Microsoft Access for school and one of the tasks was to make a search form in query, where you type for example 1. grade, 2. grade or 1st year, etc... But the field contains the name of the classes such as IT1, IT2, E1A, E3C, etc... So I could not just make a search form with [Enter Class:] or Like [Enter Class:]&"*" in the criteria column. So I was thinking, that I can use the IIF statement but it doesn't work how I imagined. I think there is a problem with the LIKE statement. I read on forums, that the IIF statement should be used in the field column but I tried the simple examples in the criteria and it worked just fine. So my question is, how I can make a search form, where I type numerous letters with one certain number in it BUT only the number will be read and returned with the same number in classes. Example: I type to search 1. grade and the value will return classes IT1, E1A, E1B, E1C, E1D. This is the line I used in the criteria column:
Like IIf([Enter the grade:]="*1*";"*1*";IIf("*2*";"*2*";IIf("*3*";"*3*";IIf("*4*";"*4*"))))
Just to qualify, I'm beginner in access and databases overall, so there is big possibility, that I'm missing something.
Thank you for help! Cheers!
Assuming input will always start with a number and you want all values containing that number, consider:
WHERE fieldname LIKE "*" & Val([Enter grade]) & "*"
Also assumes values contain only single digit.
I am using MySQL in such a way that the user enters a date and flights appear on that day.I was too lazy to put many dates so what I did was made certain flights run on certain days.
The table planes contains many columns out of which dtd(column containing many days of type varchar(50)) .
One record(in dtd) is Monday, Tuesday
The user enters the date 2018-12-03 which is a Monday.
My problem is how do I extract only the record which has Monday?(like the monday,Tuesday one)??
I tried select.....where instr(day(2018-12-03),dtd)<>0 but I realised that instr gives 0 in 2 cases
1. the character(s) is not present in the record or
2.occurence is at the beginning.
Like instr(h,hello) and instr(a,hello) gives 0.
Please help
I suggest that you use the LIKE operator.
For more info about it please check this link: SQL Like Operator
To solve your problem, you can try the following:
SELECT ...
WHERE dtd LIKE CONCAT('%', day(2018-12-03), '%');
In this case, you will get all the rows of the table, where the value of the field dtd contains the value of day(2018-12-03).
Hope this helps!
I am the beginner on the usage of MS Access.
I am going to build a program in the MS Access 2007 which can scanning some specific wordings listed in the data table from a paragraph.
For example, I want to know the occurrences of the transportation taken by the students.
(i) Therefore, I set the words "school" and "Bus" in my datatable [tableA] fields [trans].
(ii) Then, I input "I go to school by bus." in the [Input] boxes.
(iii) The result i want is that the sun of occurrences of both "school" and "Bus" can be showed in the another one textbox.
In the current situation, i just create a query [QueryA] from the [tableA] and directly use the count function in the query form. And then set the criteria as " Like [forms]![tableA]![Input] & "*" ".
However, it can just match the words in the [Input] with the final count result of the Query.
Ths a lot for providing any advice, including new direction.
I hope I understand what you're asking here, so I'll give it a stab with the information that you've provided. In your SQL window, try the following script: NOTE: You will need to change the WHERE clause to reflect your Input box(s)
SELECT Count(*) AS Expr1
FROM tableA
WHERE tableA.[trans] Like '%[Input]%;
My student table stu_table contains many different student name but most of them sound similar, in the field stu_name.
For example:
Mrinmoy, Minmay, Mrinmay, Minmoy,
Tanmoy ,Tanmay, Tonmoy, Tanmy,
Rajesh, Rajes,
Anirban, Anirbon.
Here first 5 make a similar sound group of name
Next 3 make a similar sound group of name
and last 2 make another group of similar sound name.
Can i pass more than one parameter (for example Mrinmoy and Tanmoy) within a single SOUNDEX() function to fetch both result.
If yes then how to pass it. Please help.
soundex() accept only one parameter.
So you have to use OR in sql.
You can try this sql.
SELECT * FROM `stu_table` where soundex(`stu_name`)= soundex('Anirban') OR soundex(`stu_name`)=soundex('Tonmoy')
I am trying to build a query which will look at the data in two fields in two different tables and check to see if the data is the same, if it is I want it to return the number of times it is matched, if it isn't I simply want it to return the text saying "No viewings".
I have constructed this query in my access database which has the field from the first table "Property" and the second field I want it to compare the data with, "Viewings". I have build the following expression using the build tool, however I am stuck to make it work since every time I get this error message when trying to run the query: "Your query does not include the specified expression 'Property Viewed' as part of an aggregate function."
totalViewings: IIf([Viewings]![Property Viewed]=[Property]![ID],Count([Viewings]![Property Viewed]=[Property]![ID]),"No Viewings")
Any help how to overcome this error would be very appreciated.
Thanks
I would suggest doing something like this:
1) Assuming this is something you are developing yourself, make sure your data structure is all in order first. Since I dislike relatively code-hostile identifiers, I'd have the tables as so -
Properties - PropertyID (AutoNumber, primary key), HouseNumberOrName, Street, etc.
Viewings - ViewingID (AutoNumber, primary key), PropertyID (Number/Long Integer), ViewingDate, etc.
In the Relationships view, Properties.PropertyID would then be set up to point to Viewings.PropertyID in a one-to-many relation.
2) Your actual query I would then break into two, the first to compile the data and the second to format it for display. The first would go like this, saved as ViewingCounts...
SELECT Properties.PropertyID, Count(Viewings.PropertyID) As ViewingCount
FROM Properties LEFT JOIN Viewings ON Properties.PropertyID = Viewings.PropertyID
GROUP BY Properties.PropertyID;
... and the second like this, saved as ViewingCountsForDisplay:
SELECT Properties.*, IIf(ViewingCount = 0, 'No viewings', ViewingCount) AS Viewings
FROM Properties INNER JOIN ViewingCounts ON Properties.PropertyID = ViewingCounts.PropertyID
ORDER BY Properties.PropertyID;