mysql - Set up an SQL Queries where row content is in columns -


I have a payment table with time column, payment provider column, and a revenue column.

I want to get my results in the following format:

The date payment provider total payment provider # 2 total ....

Here is the query: 'payment' name 'revenue' as in 'date' in the form of 'pay' as 'pay' as 'date', Bhugtan_ Notifikeshn_nirm_proveedr (select date Bhugtan_ Notifikeshn_ank_kriatted) (Bhugtan_ Notifikeshn_nirm_kriatted) ) And payment_notification_only M where Bhugtan_niscitkrn_nirm_kreted & gt; '1391212800' and payment_notification_name_events = payment received 'date, payment by payer;

I would like to see as the entry line deals with a line would like to see, each payment provider the amount your income as a column for each payment

Thanks

itemprop = "text">

query such an axis in which form Generally, the rows of a table or the result set are spindle in columns, it is a common practice in MySQL Area seems a little hard to do, is collected by the date.

You are doing.

But here's something like a potentially specific way to do what you need.

  DATE (payment_notification_norm_created) as 'date', SUM (IF (payment_notification_norm_provider = 'Provider 1', payment_notification_norm_revenue, 0)) `as Provider_1`, SUM (IF ('Payment_notification_norm_provider' provider2 ', payment_notification_name_review, 0)) AS' provider_`, SAM (if payment (payment_notification_non_provider = 'provider3', payment_notification_non_reyue, 0)) 'provider', 'total' in the form of SM (payment_notification_nerm_weew) Payment_notification as revenue The _nam WHERE payment_notification_norm_created & gt; = DATE ( '2014-02-01') and payment_notification_norm_event = receive payments by date 'Group (payment_notification_norm_created)  

Notice a couple of things about this.

First of all, you are right that you are summarizing both dates and providers. But you need to summarize the provider to get the pivot to work using the conditional amount.

Second, I do in fact make that MySQL raised automatically benefit from any * nix style TIMESTAMP values ​​to DATETIME values, some arithmetic your date to reduce and make it more clear . You may need to do something else.

Thirdly, you have & gt; in your sample query. It was usually wrong, and usually for the beginning of a deadline, & gt; = should be replaced with 1 February 2014 midnight or after all the payments were made, not the time that followed by at that time Now, of course, your billing department may be sleeping at midnight. But does anyone come next month and actually posted a bunch of payday payments in midnight? If

Finally, these spindle operation using a multiple that is a pain in the neck in pure SQL people choose them instead host the language or reporting package.


Comments