Jump to content

Search the Community

Showing results for tags 'group by'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 4 results

  1. I've created a course utilization report which is made up of several different MySQL queries. As you know, if a row contains no data, the result is NULL. IFNULL works to combat that, but doesn't work if there is a GROUP BY clause (GROUP BY a.courseSection). So, I need to figure out how to get it to return zero when one of the rows is null. If you look at the line Average Student Drops in the screenshot, you see that there are two cells missing which is throwing off the data. For example, since 2015 is null, everything shifts to the left. Below is the query I am using; any help with this is greatly appreciated. SELECT AVG(drops) FROM ( SELECT IFNULL(COUNT(a.stuAcadCredID),0) as drops,YEAR(a.addDate) as year FROM stu_acad_cred a LEFT JOIN course_sec b ON a.courseSection = b.courseSection LEFT JOIN course c ON b.courseID = c.courseID WHERE a.status IN('D') GROUP BY a.courseSection ) stuDrops GROUP BY year DESC LIMIT 10
  2. Hello all Have a problem with some query and i'll explain it now... I attached image file with tables which i have SELECT car.id, car.model, books.id, books.car_id, books.start_date, books.end_date FROM car LEFT JOIN books ON books.car_id = car.id WHERE books.car_id IS NULL OR books.start_date NOT BETWEEN '" . $_POST['start'] . "' AND '" . $_POST['end'] . "' AND books.end_date NOT BETWEEN '" . $_POST['start'] . "' AND '" . $_POST['end'] . "' GROUP BY books.car_id"; when car with id 1 is booked 1 time, car doesnt appears if book date range is matches to users choosen date range, but when car with id 1 is booked 3 times it appears 2 time becouse time range matched only one record of book table. i want that if time rage is matched even for one books record, dont show this car at all.. Please help with this and tanks you p.s. Sorry for my English
  3. Hi everyone, I'm trying to give my students points for doing various things on my website. Eg: Completing a quiz, getting a certain score, all result in points, which are thrown into a table called points. Now I'm trying to extract a leaderboard for the table. I'm halfway there, and have a list of scores ranked from highest to lowest, next to the member's id. See code below: $query = "SELECT point_member_id, SUM(points) FROM tbl_points GROUP BY point_member_id ORDER BY SUM(points) DESC"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo $row['point_member_id']. " : ". $row['SUM(points)']; echo "<br />"; } However, I really don't want point_member_id displaying. I'd like the student's firstname and lastname displaying. firstname and lastname are the fields 'member_firstname' and 'member_lastname' in the table 'members'. So what I need to do is extract this information where members.member_id = points.point_member_id I've tried a bunch of variations to the query and searched ad nauseum, but nothing is helping. Any advice would be greatly appreciated. Cheers, Dave
  4. A little background on the project I'm working on: I have a reasonably large number of values, over 500k rows worth. The values are generated per hour, per parent. I want to group these values by one of four time intervals: Month, week, day or hour, and get the average for this period. The challenge comes by the fact that I need to split the values into two different blocks, based upon whether the value was generated during the "day" or "night/weekend". So far I've come up with two different approaches to this: Have two fields in the table for saving the values, one for the "daytime" values and the other for "night time/weekend" values. This would allow me to run separate functions on the fields, without involving the date functions in MySQL. At the cost of having two fields for what is essentially the same type of data, and having to do the splitting in the pre-insert phase. Save all values in the same field, and then use MySQL's datetime functions with a CASE-WHEN to figure out in which block they belong. This approach seems to be the cleanest one in terms of database-design, but I fear it will put a lot of strain on the database. Especially since the SELECT statements will run more often than the insertion script. So the question is if I should go for the first approach, the second, or if there is some other solution to this that I've failed to grasp? I could really do with some expert help on this one. Example values: Desired output:
×
×
  • 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.