using 3 tables in mysql with php - mysql

I am having a hard time coming up with a JOIN statement to tie in a students score on a certain grade item. If anyone could help me get this down, it would be much appreciated.

Related

PanelMatch complains about duplicates, but I need to keep them

R Novice here that needs help.
I have an exam for which we have merged two datasets and now we want to run a PanelMatch on the dataset to estimate the ATT for staggered DiDs.
Problem: There are duplicates in the data set.
This is because R uses the firm code and year to judge about a duplicate while some firms hired two politicians in the same year, meaning there are two rows with the same firm code and year.
How can I tell R that I want to keep the duplicates / that the name of the politician should be considered when judging about duplicates?
Thanks in advance!

Amount of money the department Production spent last month on salaries in mySql queries

which query could get that going for me please? having a hard time!I am trying to write as a query in mysql using a sample employee database.
I suggest you post what you are currently trying to do. We won't do your homework for you.
Some reading you might want to do:
http://forums.mysql.com/
SQL- Add up Values in a Column
http://www.tutorialspoint.com/mysql/mysql-where-clause.htm
Good MySQL primer / learning resources
The statement would be in the ballpark of:
select sum(Production) as MyColumnSum from departments

Individual ranking system causing Database crashes => Revert to Individual Tables?

I ask a similar question (1 table 150,000,000,000 rows) now I will add some details.
500,000 Items
Unlimited # Categories
15 Sections
The site allows users to create their own categories and place as many items into that category. Before they can add anything they must choose what section the category is best represented.
Each of the above will have: id, title, description, imageURL
I have two issues:
Each CATEGORY/ITEM will beable to re-arrange items/categories greatest to worst. COLUMN: rank
Users will be acknowledged for contributing most to category. COLUMN: king
This feature of the site is pretty simple but the ranking process is throwing me for a loop. I have tried multiple test runs cramming as much data into one table as possible but the results are crashing my spirits. The division of data to tables is not easy because of the individual ranking for each category.
The original design was to Have the above 3 and individual tables of each category/item to allow individual ranking(boost speed/performance) then:
User contributor: sectionID, categoryID, itemID, userID
Individual Rank: categoryID/itemID, rank
The outcome would be 150,000,000,000 tabled labyrinth. Has anyone dealt with this concept before? What is the best plan of action? Am I on the right track?
I just got High Performance MySQL, 3rd Edition
Optimization, Backups, and Replication and Beginning PHP and MySQL: From Novice to Professional 4th (fourth) EditionI am not promoting or endorsing these books...
These are the first of many steps I will be taking to tackle this design problem I face. Any comments and assistance will be appreciated. Thoughts; Concerns??

How should I setup the structure of my MySQL database to work for my needs?

I am working on an application that awards the top person of each category for being first. The way you become first in a category is by having the most number of votes in the past 30 (or so) days. So even if you had a total of 2,000 votes but got only 2 votes within the past 30 days, someone with 10 votes but got all 10 within the past 30 days would be ranked above you. I am just trying to seek advise on the best way to create this type of system with a MySQL database and how to structure the database.
I am pretty unsure of the best way to go about this, any advice would be greatly appreciated!
The first desicion you have to make is, whether you want to keep a record for every vote cast: This has the potential for a huge table, but it lets you keep a lot of information, so you trade storage and performance against information. This must be answered by business logic, not implementation.
Assuming you DO want to keep every vote, keep it with a timestamp and the only thing you have to do is to join the user person table with the vote table, use a WHERE clause to select only the last N days and a COUNT() aggregate to count your votes.
If you do NOT want to keep every vote, you should have an accumulation table with person, day and votecount - an analogous query with SUM() instead of COUNT() will do what you want.

Can someone please help me with this sql query?

So at my job ive been asked to fix some sql code running on mysql 5 database and im stuck, also im not sure if this is the right place to do this but there is a small beer bounty on this question. Well send the top voted question some beer monies.
Basically the statement needs to do the following:
Delete the row from customers_basket where products.products_quantity < 1 AND LOWER(inventory_t_product_minimum_stock.minimum_quantity) = 'nla'
This is the current statement:
DELETE FROM customers_basket
WHERE EXISTS
(SELECT products_id
FROM inventory_t_product_minimum_stock
WHERE customers_basket.products_id =
inventory_t_product_minimum_stock.products_id
AND LOWER(inventory_t_product_minimum_stock.minimum_quantity) = 'nla')
So really all that needs to change is add the bit about products_quantity < 1 however, that information comes from a different table.
Writing a simple left join for 3 tables wouldn't be difficult, my concern however is that this code is executed when the user logs in and joining three large tables would be a pretty big issue for us i imagine. Im actually a C developer come javascript coder some dbs are a little outside my area of expertise. Would one of the sql gurus out there have a good solution with out having to change our db schema?
edit* spelling
As long as your tables are properly indexed, and you're joining on the indexed fields, and your filters are targeting an indexed field, the query should perform fairly well.
Also, are you only deleting items in the customer basket table for the user logging in or for all products that have a quantity of < 1?