Mam następujące zapytanie MySQL:MySQL zbiorczy logiczne
select
members_categories.category_desc as 'membership_type',
SUM(CASE payment_method WHEN 'Bank Transfer' THEN amount_paid ELSE 0 END) AS 'Bank Transfer',
SUM(CASE payment_method WHEN 'Cash' THEN amount_paid ELSE 0 END) AS 'Cash',
SUM(CASE payment_method WHEN 'Cheque' THEN amount_paid ELSE 0 END) AS 'Cheque',
SUM(CASE payment_method WHEN 'Credit Card' THEN amount_paid ELSE 0 END) AS 'Credit Card',
SUM(CASE payment_method WHEN 'Direct Debit' THEN amount_paid ELSE 0 END) AS 'Direct Debit',
SUM(CASE payment_method WHEN 'PayPal' THEN amount_paid ELSE 0 END) AS 'PayPal',
SUM(CASE payment_method WHEN 'Salary Deduction' THEN amount_paid ELSE 0 END) AS 'Salary Deduction',
SUM(CASE payment_method WHEN 'Standing Order' THEN amount_paid ELSE 0 END) AS 'Standing Order',
SUM(amount_paid) AS 'Total'
FROM members_main, members_categories, members_payments
WHERE members_categories.category_code=members_main.membership_type and members_main.contact_id=members_payments.contact_id and members_payments.payment_date between '2012-01-01' and '2013-12-31'
GROUP BY membership_type With ROLLUP
Które zwraca:
Jak widać z powyżej sumy ROLLUP na dole pokazuje descrption z membership_type pole ostatniego wiersza zwrócone. Czy istnieje sposób, aby zastąpić to słowem Total?
Chłodny nie wiedział o 'ROLLUP' – Neal
Nie. Nie ma takiej opcji w składni mysql. Będziesz musiał wykryć duplikat nazwy pod warunkiem, że pierwsza instancja zrolowanego pola jest wartością pierwotną, a kolejną wartością jest rollup. –
według dokumentacji, ta wartość komórki powinna mieć wartość "NULL". Coś tu jest podejrzanego. http://dev.mysql.com/doc/refman/5.0/en/group-by-modifiers.html –