2016-12-15 7 views
0

i eine SQL-Abfrage wie habenwie Summe der Datensätze erhalten nach Datum

SELECT t2.net 
    , t1.date 
    FROM database1.invoices t1 
    join invoicesdetail t2 
    on t1.id = t2.InvID 
where shopid = 11 
    and t1.date between '2016-01-30' AND '2016-01-31' 
    AND t2.StockType = 1 

` unter Verwendung von oben Abfrage Ich habe Aufzeichnungen wie

net date 
120 2016-01-30 
115 2016-01-20 
35 2016-01-31 
170 2016-01-31 

Ich möchte nur diese Datensätze berechnen datewise 2016-01-30 total 235 und 2016-01-31 Gesamt ist 205 und insgesamt ist 440 bitte helfen Sie mir diese Anfrage zu erstellen

+0

Siehe http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a -very-simple-sql-query – Strawberry

Antwort

0
SELECT SUM(t2.net), t1.date 
FROM database1.invoices t1 
JOIN invoicesdetail t2 ON t1.id = t2.InvID 
WHERE shopid='11' 
AND t1.date between '2016-01-30' AND '2016-01-31' 
AND t2.StockType=1 
GROUP BY t1.date 
UNION 
SELECT SUM(t2.net), 'TOTAL' 
FROM database1.invoices t1 
JOIN invoicesdetail t2 ON t1.id = t2.InvID 
WHERE shopid='11' 
AND t1.date between '2016-01-30' AND '2016-01-31' 
AND t2.StockType=1 
+0

Vielen Dank ist workssss – Anukul

1

Zusammenfassend:

SELECT sum(t2.net), t1.date 
FROM database1.invoices t1 
JOIN invoicesdetail t2 ON t1.id = t2.InvID 
WHERE shopid='11' AND t1.date BETWEEN '2016-01-30' AND '2016-01-31' AND t2.StockType=1 
GROUP BY t1.date 
Verwandte Themen