Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> zsumowanie dwóch kolumn
mb83
post
Post #1





Grupa: Zarejestrowani
Postów: 113
Pomógł: 0
Dołączył: 2.02.2012

Ostrzeżenie: (0%)
-----


witam
mam zapytanie które pobiera wartość dwóch tabel (dwa count)
  1. select (select count(id) from table1) as ile1,
  2. (select count(id) from table2) as ile2 from dual


o powiedzmy, że wynik to:
  1. ile1 ile2
  2. 16 3


a jak je zsumować razem, żeby efekt był

  1. total
  2. 19


Wiem, że musi być sum() tylko niewiem jak go poprawnie skonstruować.

Ten post edytował mb83 4.11.2014, 17:09:42
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
mb83
post
Post #2





Grupa: Zarejestrowani
Postów: 113
Pomógł: 0
Dołączył: 2.02.2012

Ostrzeżenie: (0%)
-----


dokładnie (prawie) zapytanie wygląda tak:
  1. select sum(*) from
  2. (select count(id) from table1 where '2014-11-07' between od and do
  3. union
  4. select count(id) from table2 where '2014-11-07' between od and do)


ale nie działa, chyba coś musi być inaczej.
Błąd:
  1. #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) from (select count(id) from table1 where '2014-11-07' between od and do un' at line 1
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 12:16