I'm using Google Drive Spreadsheets and need to create a report - how do I do this logical query? - spreadsheet

I've got a spreadsheet that has the headings Operation, Priority and Specialty so all of the information for a specific operation is on one line and is stored as text.
I need to create a report for each Specialty that tells me the number of Operations done, which is easy (using COUNTIF), but also how many routine or urgent Priority Operations there were.
This would be easy in a database. I'd do it like this.
COUNT * FROM OPERATION_LIST
WHERE Specialty = "Cardiac"
AND Priority = "Routine";
I cannot for the life of me work out how to do this in Spreadsheet though.
I know Google Drive Spreadsheets have a QUERY function but I cannot work out how to use it for this and Googling for answers is no help. I'm sure it'll be obvious when I see it but I've been working on this for days now, with no luck.
Can anyone help?

I would do it like this:
=query(A:C, "select A,count(B) where B = 'Routine' and C = 'Cardiac' group by A label count(B) 'Count'",1)
Assuming that you have a header row (Operation, Priority, Speciality, which represent A,B,C in the query - respectively).
Hope this helps.

Related

Is it possible to use SQL to show the average of some values in one column and then in subsequent columns display the individual values?

I have a bunch of data and I want the output to display an average of all the data points but also the individual data points in subsequent columns. Ideally it would look something like this:
Compound | Subject | Avg datapoint | Datapoint Experiment 1 | Datapoint Exp 2 | ...
..........XYZ......|.....ABC....|............40...............|...............20..............................|...............60...............|......
..........TUV......|.....ABC....|............30...............|...............20..............................|...............40...............|......
..........TUV......|.....DEF....|............20...............|...............10..............................|...............30...............|......
One problem I'm running in to is that I get repetitive lines of information. Another is that I have some rows pulling in info that doesn't apply, such that some of the individual datapoints in, say, row 2 would have info from subject DEF when I only want it to have info from subject ABC.
I hope this makes sense! I'm currently using inner join with a ton of where qualifiers. I'm close but not quite there. Any help is appreciate and let me know if I can provide additional info to help you help me.
The SQL language has a very strict rule requiring you to know the exact number of columns for your result set in advance, before looking at any data in your tables.
Therefore, if this average is based off a known fixed number of columns, or if the number of potential columns is reasonably small, where you can manually setup placeholders, then this will be possible. The key search terms to learn how to do this is "conditional aggregation", where you may also need to join the table to itself for each field.
Otherwise, you will need to pivot and aggregate your data in your client code or reporting tool.

Store Multiple Values in a Single Textbox in Microsoft Access

I've searched a lot of forums but can't find the exact answer I need.
My db is a Conference Scheduling DB whereby I have four tables to consider:
Persons / Person-to-Conference / Conference_Main / Conference_Day
I am unable to post images because when I try to do so on my work computer, it craps out, so I'm sorry for the lack of visual.
This db will allow someone to create a conference, where it will automatically populate data for Day 1. Not all conferences are multiple days, but some are.
Let's say there's a three-day conference (Conference X), and it's attended by three people (A, B, C).
Person A is going Day 1
Person B is going Day 1 & 3
Person C is going Day 2 & 3
I have a query where I want to show what days of the conference people attended and I want to populate a textbox on a form with that information. Is there a simple concatenation I can do, or do I need a For Each loop, because of the question of whether or not a conference will even have multiple days or not?
I want to see something like this:
Attendee Days Attended
Person A 1
Person B 1, 3
Person C 2, 3
*Note "Days Attended" would be the textbox in question where I'd want to see the multiple values, e.g. "2, 3"
I'd rather not store this in another table, but rather just make it Dynamic based on whatever days I know my person is going to for the conference. Can anyone help me with some vba?
Or should this instead be a Query that will concatenate the Days attended? Is that possible?
My answer has nothing to do with it being entered in correctly (it is), but rather is a question of where I should be calling the variable arguments for the WHERE statement.
I received a ton of help here: AccessForums which made reference to this post on AllenBrowne.com. Thank you to all that helped!
Someone helped me with my WHERE statement from that AllenBrowne.comblink. It needed to look something like this:
I needed to add this to the control source of the textbox:
=ConcatRelated("Day", "qry_PerToConfByDay", "PersonID=" & [PersonID] & " AND Conference ID=" & [ConferenceID]
Whereby:
Start of Function is: ConcatRelated(
Field I want to see all values is: "Day",
Table (or in this case the Query) I want to pull the data from: "qry_PerToConfByDay",
Where criteria, setting up which fields I want to pull from: "PersonID=" & [PersonID] & " AND ConferenceID=" & [ConferenceID]
End the function: )
I didn't need to do an ORDER BY nor did I need to change my delimiter, so the last two arguments I didn't put in. But that's what worked for me.
I hope this is helpful to someone else!

Querying via a form with value from textbox as criteria

The situation: metadata about biological specimens are collected in an Access table. The specimens come from human patients and patient data are collected in a separate table. To limit the amount of private health information we have hanging around, the patient database must be updated with new patients only when we actually receive samples from them.
So that the data entry workers know when they need to update the patient table, I want a button in the specimen data entry form that will pass an entered patient id value as criteria to a query.
The query looks like this right now:
SELECT Patients.[Patient id]
FROM Patients
WHERE (((Patients.[Patient id])=[Forms]![Specimen entry]![patient id]));
but it never has results, even when I run it from records that I know correspond to patients in the patient table. How do I fix this?
Suggestions about what to call this situation so that I can make better searches about it would also be appreciated. I'm an Access novice.
The query looks correct, but make sure the WHERE clause is comparing numbers to numbers or strings to strings (not a number to a string). Also confirm that the form and textbox names are correct. A quick test using your query worked for me.
Depending on how you plan to present the information, you can also dynamically create the query in VBA and then pass the information to the form.
For searching, I'd recommend some combination of access, dynamic, query, and vba.
alternative option
If you're only looking to see if a single patient exists in the table, it may be simpler to use the dlookup function:
If IsNull(DLookup("[Patient ID]", "Patients", "[Patient ID]='" & Me.Patient_ID & "'")) Then MsgBox "does not exist"
This will check to see if the patient exists (return a number) or does not exist (returns NULL).
https://support.office.com/en-us/article/DLookup-Function-8896cb03-e31f-45d1-86db-bed10dca5937

exporting only rows from sql in phpmyadmin, only where a certain column has Boolean of 0

"meta/background about the use of code and person using it"
1.site built by professional that left company,
2.I am inexperienced but trying/ want to learn,
3.Customer support site for service reps,
................................................
What im trying to do exactly per stackoverflows parameters.
We have a drop down box listing issues that the customer had in a column labeled "issue_type". I can export via csv entire table load onto excel then give to boss for overall review of what the issues were. However data base has a "hide" column. Its function is that when the row is updated the record is kept but the same "job or call" has only one viewable report on site (the most recently updated one). Hide is a boolean. In conclusion I want to export rows that only has the "hide" column Boolean status at 0, AND to only export the columns "customer", and "issue_type". I can seem to only do one or the other. and have researched a minimum of 4 hours to find answer myself and cannot find a syntax to do both at the same time with phpmyadmin.
I dont want an enormous data that is mostly useless but for issue type and customer but i will have to manually delete all the rows with hide = 1?
Thanks anyone 1st attempt question sorry if not correct for stackflow.
SELECT Customer,Issue_type FROM tickets where hide =0;
Elaborating on what is above for anyone that may be looking for a similar answer, SQL supports the "where" clause of which you can when properly syntaxed select many of your columns and their associated strings, booleans, and numbers to = what your looking for. Wildcards I found later for other uses work as well.
Sorry about the self answer but hopefully someone finds this usefull

what is the best way to record users searches and count how many times it has been queried?

I am not sure what SQL is exactly, databases I think, would SQL be the thing to use?
I want it so that when a user types into a search box it displays a "did-you-mean" box, that also shows how many other people used that term but I will do later ;)
currently I just want the text to be saved into database (?) and also how many times it's been done.
(new to stackoverflow so sorry if format/whatever is bad)
You just need a three table named something like search_queries which has columns for: id, search_text, and count. Everytime somebody searches just increment the count column where search_text is equal to what they searched for. This is a really broad question though and you need to start by learning the basics and report back here with more specific questions.