Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table like this in oracle sql view

USER_ID DATE LOGIN_COUNT
1 1 2
1 2 4
1 3 5
2 1 6
2 2 7

I want to display it in php using the following format

USER ID 1 2 3 . . . 31 TOTAL AVERAGE OF LOGIN
1 2 4 5 11 0.35483871
2 6 7 0 13 0.419354839

Is it possible to create a table like this in php ?
Any help would be appreciated
Posted
Comments
ZurdoDev 28-Dec-15 8:08am    
First off, if it can be done do it in Oracle.
Secondly, it is not clear how you are getting your output.

I certainly hope you're actually not storing dates as integers, but since your example data implies that, I have made my solution accordingly.
SQL
WITH avgview AS (
    SELECT  user_id
        ,date
        ,login_count
        ,Avg(login_count) OVER (PARTITION BY user_id) avgcount
    FROM    VIEW
    )
SELECT  *
FROM    avgview
PIVOT   (
    Sum(login_count)
    FOR DATE IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)
    )
 
Share this answer
 
when you do the SQL command, use AS e.g.

Select
t1.a as a1,
t1.b as b1,
t1.c as c1,
t2.a as a2,
t2.b as b2,
t2.c as c2
from table1 t1
join table2 t2 on t2.id = t1.id //note this join may not be correct in your case
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900