Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I am well aware that the from and to dates are passed as search parameters and are are not in the database but that doesn't mean they do not have a format. If you echo $_POST['from'] and $_POST['to'], what do they look like?
  2. my data mysql> SELECT * FROM history; +-----------+----------+--------------+-------------+ | historyid | memberid | last_payment | amount_paid | +-----------+----------+--------------+-------------+ | 1 | 1 | 2015-12-20 | 1000.00 | | 2 | 1 | 2016-01-01 | 150.00 | | 3 | 1 | 2016-01-10 | 50.00 | | 4 | 1 | 2016-02-03 | 60.00 | | 5 | 1 | 2016-02-25 | 40.00 | | 6 | 1 | 2016-05-30 | 300.00 | | 7 | 1 | 2016-06-22 | 200.00 | | 8 | 2 | 2016-01-05 | 155.00 | | 9 | 2 | 2016-02-14 | 205.00 | +-----------+----------+--------------+-------------+ mysql> SELECT * FROM quarters; +-----+ | qtr | +-----+ | 1 | | 2 | | 3 | | 4 | +-----+ the query and results - I told you to put the conditions on the history table into the ON clause, not in the WHERE clause. mysql> SELECT qtr AS Quarter, SUM(amount_paid) as Total -> FROM quarters q -> LEFT JOIN history h ON qtr = QUARTER(last_payment) -> AND YEAR(last_payment) = YEAR(CURDATE()) -> AND memberid = '1' -> GROUP BY qtr; +---------+--------+ | Quarter | Total | +---------+--------+ | 1 | 300.00 | | 2 | 500.00 | | 3 | NULL | | 4 | NULL | +---------+--------+ If you have them in the WHERE clause then the LEFT JOIN behaves as as an INNER JOIN like this mysql> SELECT qtr AS Quarter, SUM(amount_paid) as Total -> FROM quarters q -> LEFT JOIN history h ON qtr = QUARTER(last_payment) -> WHERE YEAR(last_payment) = YEAR(CURDATE()) -> AND memberid = '1' -> GROUP BY qtr; +---------+--------+ | Quarter | Total | +---------+--------+ | 1 | 300.00 | | 2 | 500.00 | +---------+--------+
  3. What format are a ) sales_month? b ) from and to dates?
  4. Add a WHERE clause to your queries
  5. Do you have a record for each quarter in the quarters table? And as you are left joining to the history table, put those conditions in the ON clause instead of the WHERE clause (ie change "WHERE" to "AND" in your query)
  6. Why are you storing numeric values formatted with commas in the first place. You should do the formatting only on final output. Also, to do this you must be storing them in character fields which wrong.
  7. Correct, it won't work in that case. But that is the nature of joins. If you join one record with two matching records then the data from the one goes into both resulting records.
  8. SELECT DISTINCT Courses.CourseTitle ...
  9. You can use sql's STR_TO_DATE() function. Concatenate "-01" to the end first so you don't get day 0. Example CREATE TABLE `test_date` ( `id` int(11) NOT NULL AUTO_INCREMENT, `str_date` varchar(20) DEFAULT NULL, `date` date DEFAULT NULL, PRIMARY KEY (`id`) ) mysql> SELECT * FROM test_date; +----+----------+------+ | id | str_date | date | +----+----------+------+ | 1 | 16-Jan | NULL | | 2 | 16-Feb | NULL | | 3 | 16-Mar | NULL | +----+----------+------+ UPDATE test_date SET date = STR_TO_DATE(CONCAT(str_date, '-01'), '%y-%b-%d'); mysql> SELECT * FROM test_date; +----+----------+------------+ | id | str_date | date | +----+----------+------------+ | 1 | 16-Jan | 2016-01-01 | | 2 | 16-Feb | 2016-02-01 | | 3 | 16-Mar | 2016-03-01 | +----+----------+------------+
  10. Use AND instead of OR. Alternatively, ... WHERE idsala NOT IN (23,24,39)
  11. You need to join twice to teamlookup using different aliases INNER JOIN `teamlookup` AS tlh ON tg.home = tlh.websitedb INNER JOIN `teamlookup` AS tla ON tg.away= tla.websitedb
  12. I see you have a column called "tags", which rings alarm bells for me, How are you storing the data in that column?
  13. see http://pitmanshorthand.homestead.com/BasicsofPitman.html
  14. Those 1's should be l (lowercase L)
  15. You have given no information about the table in the query, other than its name, so how do you expect us to help?
  16. Add a WHERE clause to your query
  17. You need to join them via the lookup table SELECT postname , name FROM posts p JOIN lookup l ON p.id = l.postid JOIN postcategory c ON l.categoryid = c.id
  18. One query killer you have in there is " ... LIKE '%XXX%' ... " That leading "%" will prevent the query from using an index so every record must be scanned. Without knowing the exact nature of the search (what is in the $parts array?) I can't say more, except, maybe, try a FULLTEXT search
  19. One easy option is to create HTML or PDF files. Word will open those and you can save as DOCX
  20. Sorry, I am unable to do that, I have never read one. Just reference manuals and experimentation.
  21. Sorry, I copied and edited the wrong query SELECT c.name AS county_name , c.id AS county_id , c.population , group_concat(DISTINCT r.name separator '<br /> ') AS recruiter , group_concat(DISTINCT u.name separator '<br /> ') AS u_name FROM counties c INNER JOIN states s ON c.state_id = s.id LEFT JOIN recruiters r ON r.county_id = c.id LEFT JOIN universities u ON c.id = u.county_id WHERE c.state_id = $StateID GROUP BY c.name
  22. try SELECT c.name AS county_name , c.id AS county_id , c.population , group_concat(DISTINCT r.name separator '<br /> ') AS recruiter , group_concat(DISTINCT u.name separator '<br /> ') AS uname FROM counties c INNER JOIN states s ON c.state_id = s.id LEFT JOIN recruiters r ON r.county_id = c.id UNION RIGHT JOIN recruiters r ON r.county_id = c.id LEFT JOIN universities u ON r.county_id = u.county_id WHERE c.state_id = 5 GROUP BY c.name results +--------------------+-----------+-----------+ | region | region_id | parent_id | +--------------------+-----------+-----------+ | Caribbean | 1 | 0 | | Eastern Caribbean | 1 | 1 | | Southern Caribbean | 1 | 1 | | Western Caribbean | 1 | 1 | | South America | 4 | 0 | | Amazon River | 4 | 4 | +--------------------+-----------+-----------+
  23. What is the group table for when you have the region parent in the region table? Try SELECT reg_name as region , region_id , parent_id FROM clc_crz_regions WHERE parent_id=0 UNION SELECT r1.reg_name , r2.region_id , r1.parent_id FROM clc_crz_regions r1 INNER JOIN clc_crz_regions r2 ON r1.parent_id = r2.region_id WHERE r2.parent_id=0 ORDER BY region_id, parent_id, region +--------------------+-----------+-----------+ | region | region_id | parent_id | +--------------------+-----------+-----------+ | Caribbean | 1 | 0 | | Eastern Caribbean | 1 | 1 | | Southern Caribbean | 1 | 1 | | Western Caribbean | 1 | 1 | | South America | 4 | 0 | | Amazon River | 4 | 4 | +--------------------+-----------+-----------+
  24. I meant to use that in your earlier query SELECT c.name AS county_name , c.id AS county_id , c.population , group_concat(r.name separator '<br /> ') AS recruiter , group_concat(u.name separator '<br /> ') AS u_name FROM counties c INNER JOIN states s ON c.state_id = s.id LEFT JOIN recruiters r ON r.county_id = c.id LEFT JOIN universities u ON c.id = u.county_id WHERE c.state_id = $StateID GROUP BY c.name
  25. Easiest way is to store all in the category table. The parent id of of top-level categories will be NULL, in subcats it's the id of the parent category TABLE: articles TABLE: categories articleID +------ catID ---+ title | cat_name | content | parentCatID >--+ catID >-----+
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.