I'm trying to count product numbers for a period of time there are three tables.
invoice
invoicenumber datefinish
invoiceDetails
invoicenumber productnumber
products
name productnumber
I need the result set to include the: datefinish, name, productnumber and the count of the productnumber by datefinish order by datefinish, productnumber.
I can get a count of all productnumbers from the invoiceDetails like this.
select i.productnumber , c.cnt from invoicedetails i
INNER JOIN (SELECT productnumber , count(productnumber ) as cnt
FROM invoicedetails GROUP BY productnumber ) C ON i.productnumber = C.productnumber
But if I add another table in the select i get and error and if I add a where in the JOIN i get and error. I tried to just get all but then I get a error: 'Invalid comparison or operation on strings with different collations.'
Select d.productnumber, p.name, t.datefinish from invoicedetails d, invoice t, product p where d.invoicenumber = t.invoicenumber and
d.productnumber=p.productnumber and t.datefinish >= '01/01/2015' and t.datefinish <= '01/31/2015'
order by t.datefinish, d.productnumber
Thanks for any help, Kim
Aucun commentaire:
Enregistrer un commentaire