Jump to content

Joins


craygo

Recommended Posts

is there a need to give the tables aliases??

 

this is what I have in my sql statement

$qx = "SELECT roster.handle AS 'name', roster.real_name AS 'rname', ";
$qx .= "EXTRACT(YEAR FROM servpay.paydate) AS 'YEAR', ";
$qx .= "SUM(IF(servpay.paymonth = 1, servpay.amount, 0)) AS 'JANUARY', ";
$qx .= "SUM(IF(servpay.paymonth = 2, servpay.amount, 0)) AS 'FEBRUARY', ";
$qx .= "SUM(IF(servpay.paymonth = 3, servpay.amount, 0)) AS 'MARCH', ";
$qx .= "SUM(IF(servpay.paymonth = 4, servpay.amount, 0)) AS 'APRIL', ";
$qx .= "SUM(IF(servpay.paymonth = 5, servpay.amount, 0)) AS 'MAY', ";
$qx .= "SUM(IF(servpay.paymonth = 6, servpay.amount, 0)) AS 'JUNE', ";
$qx .= "SUM(IF(servpay.paymonth = 7, servpay.amount, 0)) AS 'JULY', ";
$qx .= "SUM(IF(servpay.paymonth = 8, servpay.amount, 0)) AS 'AUGUST', ";
$qx .= "SUM(IF(servpay.paymonth = 9, servpay.amount, 0)) AS 'SEPTEMBER', ";
$qx .= "SUM(IF(servpay.paymonth = 10, servpay.amount, 0)) AS 'OCTOBER', ";
$qx .= "SUM(IF(servpay.paymonth = 11, servpay.amount, 0)) AS 'NOVEMBER', ";
$qx .= "SUM(IF(servpay.paymonth = 12, servpay.amount, 0)) AS 'DECEMBER' ";
$qx .= "FROM roster LEFT JOIN servpay on roster.id=servpay.playid ";
$qx .= "WHERE roster.title= 'OWNER' ";
$qx .= "GROUP BY YEAR ";
$qx .= "ORDER BY roster.id ";

 

I have it being grouped by year but what happens when I insert a person for the year 2006 everyone's name goes away accept the one person that has paid for 2006.

Link to comment
https://forums.phpfreaks.com/topic/2558-joins/#findComment-8492
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.