2012-08-15 14 views
5

Ostatnio utworzyłem zapytanie, które kompiluje się pomyślnie i zwraca pożądany wynik. Kiedy użyłem tego fragmentu kodu jako podkwerendy w innym kawałku kodu, który pojawił się dla mnie na stackoverflow, napotkałem kilka problemów, które ostatecznie rozwiązano. Próbowałem użyć tego zapytania jako podkwerendy w tym kodzie podanym mi. Jednak sql fiddle nic nie zwraca. Brak błędów lub skompilowanych wiadomości. Kiedy próbowałem wstawić błąd składni celowo - jak losowy znak +, nic się nie stało. czy to dlatego, że zapytanie jest zbyt długie?Czy istnieje ograniczenie możliwości obsługi plików sql fiddle? Polecenie sql fiddle nie kompiluje niczego i nie zwraca komunikatów o błędach.

schematu

CREATE TABLE sampleData 
    (
    id MEDIUMINT NOT NULL AUTO_INCREMENT, 
     timecode int, 
    count int, 
     PRIMARY KEY (id) 
    ) 
#ENGINE=MyISAM 
; 

INSERT INTO sampleData 
(timecode, count) 
VALUES 
(1344893440, 1), (1346014720, 1),(1344898688,1),(1345654784,1),(1345978368,1), 
(1345959296,1), (1345064704,1), (1345156352,1),(1345225600,1), 
(1345017984,1),(1345640960,1),(1346019968,1),(1345834752,1), 
(1345438464,1),(1344986880,1),(1345045632,1),(1345557888,1),(1344973056,1),(1345087232,1),(1345433216,1),(1345691008,1), 
(1344917760,1),(1345253248,1),(1344934912,1),(1345890048,1),(1345272448,1), (1345829504,1),(1345798400,1),(1345203200,1),(1344741120,1), 
(1345175552,1),(1344824192,1),(1344926336,1),(1345571712,1),(1344931584,1),(1345211776,1),(1345059456,1),(1345516288,1),(1345441920,1),(1346009472,1) 

zapytania

select t_0.*, 
      (coalesce(t_3.average_number_of_votes_per_previous_period_days, 0) - coalesce(t_4.average_number_of_votes_per_previous_period_days, 0)) * 100.0 
    from 
     (select t.*, 
      (coalesce(t_1.count, 0) - coalesce(t_2.count, 0)) * 100.0 as "percentage increase in count in %" 
    from 
    (
     SELECT sum(1) AS ordr, 
     t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 

     FROM 
     (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
     FROM sampleData 
     GROUP BY DAY) t1 
     INNER JOIN 
     (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
     FROM sampleData 
     GROUP BY DAY) t2 
     on t1.day >= t2.day                                 
     GROUP BY t1.day, t1.count 
     ORDER BY t1.day 
     )t 
     left outer join 
     (
      SELECT sum(1) AS ordr, 
      t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 
      FROM 
      (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
      FROM sampleData 
      GROUP BY DAY) t1 
      INNER JOIN 
      (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
      FROM sampleData 
      GROUP BY DAY) t2 
      on t1.day >= t2.day                                 
      GROUP BY t1.day, t1.count 
      ORDER BY t1.day 
     )t_1 
     on t.ordr = t_1.ordr + 1 left outer join 
     (
      SELECT sum(1) AS ordr, 
      t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 
      FROM 
       (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
       FROM sampleData 
       GROUP BY DAY) t1 
      INNER JOIN 
       (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
       FROM sampleData 
       GROUP BY DAY) t2 
      on t1.day >= t2.day                                 
      GROUP BY t1.day, t1.count 
      ORDER BY t1.day 
      ) t_2 
     on t.ordr = t_2.ordr + 2)t_0 
    left outer join 
     (select t.*, 
      (coalesce(t_1.count, 0) - coalesce(t_2.count, 0)) * 100.0 as "percentage increase in count in %" 
    from 
    (
     SELECT sum(1) AS ordr, 
     t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 

     FROM 
     (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
     FROM sampleData 
     GROUP BY DAY) t1 
     INNER JOIN 
     (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
     FROM sampleData 
     GROUP BY DAY) t2 
     on t1.day >= t2.day                                 
     GROUP BY t1.day, t1.count 
     ORDER BY t1.day 
     )t 
     left outer join 
     (
      SELECT sum(1) AS ordr, 
      t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 
      FROM 
      (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
      FROM sampleData 
      GROUP BY DAY) t1 
      INNER JOIN 
      (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
      FROM sampleData 
      GROUP BY DAY) t2 
      on t1.day >= t2.day                                 
      GROUP BY t1.day, t1.count 
      ORDER BY t1.day 
     )t_1 
     on t.ordr = t_1.ordr + 1 left outer join 
     (
      SELECT sum(1) AS ordr, 
      t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 
      FROM 
       (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
       FROM sampleData 
       GROUP BY DAY) t1 
      INNER JOIN 
       (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
       FROM sampleData 
       GROUP BY DAY) t2 
      on t1.day >= t2.day                                 
      GROUP BY t1.day, t1.count 
      ORDER BY t1.day 
      ) t_2 
     on t.ordr = t_2.ordr + 2) t_3 
     on t.ordr = t_3.ordr + 1 
    left outer join 
     (select t.*, 
      (coalesce(t_1.count, 0) - coalesce(t_2.count, 0)) * 100.0 as "percentage increase in count in %" 
    from 
    (
     SELECT sum(1) AS ordr, 
     t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 

     FROM 
     (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
     FROM sampleData 
     GROUP BY DAY) t1 
     INNER JOIN 
     (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
     FROM sampleData 
     GROUP BY DAY) t2 
     on t1.day >= t2.day                                 
     GROUP BY t1.day, t1.count 
     ORDER BY t1.day 
     )t 
     left outer join 
     (
      SELECT sum(1) AS ordr, 
      t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 
      FROM 
      (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
      FROM sampleData 
      GROUP BY DAY) t1 
      INNER JOIN 
      (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
      FROM sampleData 
      GROUP BY DAY) t2 
      on t1.day >= t2.day                                 
      GROUP BY t1.day, t1.count 
      ORDER BY t1.day 
     )t_1 
     on t.ordr = t_1.ordr + 1 left outer join 
     (
      SELECT sum(1) AS ordr, 
      t1.id,t1.day, t1.count, SUM(t2.count) as aggregate, (SUM(t2.count)-t1.count)/(sum(1)-1) as "average_number_of_votes_per_previous_period_days" 
      FROM 
       (SELECT id, date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
       FROM sampleData 
       GROUP BY DAY) t1 
      INNER JOIN 
       (SELECT date(FROM_UNIXTIME(timecode)) AS day,(FROM_UNIXTIME(timecode)) AS original, COUNT(1) as 'count' 
       FROM sampleData 
       GROUP BY DAY) t2 
      on t1.day >= t2.day                                 
      GROUP BY t1.day, t1.count 
      ORDER BY t1.day 
      ) t_2 
     on t.ordr = t_2.ordr + 2) t_4 
     on t_0.ordr = t_4.ordr + 2 
+1

Dodanie zapytania do pytania może pomóc. Przykład SQLFiddle może pomóc jeszcze bardziej. –

+1

Problem polega na tym, że fiddle sql nie kompiluje się. więc nie otrzymuję linku do zapytania. ale opublikuję zapytanie. jest naprawdę długi: – user1569897

+0

Może powinieneś również dołączyć instrukcję create table + insert. (Zwłaszcza, że ​​twórca SQLFiddle Jake Feasel prawdopodobnie znajdzie to pytanie.) BTW, czy twoje zapytanie działa na przykład na phpMyAdmin? – biziclop

Odpowiedz

5

mam podłączony zapytanie w this skrzypcach, a teraz widzę problemu. Twoje zapytanie ma ponad 8000 znaków (dokładnie 8423) i nie wyświetlam tego komunikatu na panelu wyników. Zasadniczo jest to błąd wyświetlania w Fiddle SQL, którego wcześniej nie zauważyłem (dlatego, dziękuję za zwrócenie na to uwagi!).

W międzyczasie można spróbować wyciąć niektóre z postaci, aby zmieściły się w limicie 8000 znaków.

+1

Co ciekawe, jeśli po prostu kliknę "Formatuj SQL" z zapytaniem, zmniejszy to liczbę znaków do limitu 8000: http: // sqlfiddle. com/#! 2/97a57/1 –

+0

dziękuję. Próbowałem go w phpmyadmin i działa. – user1569897