noxqs.org's

FROG
FRee-open-source project-lOG

30/8/2007

Welke records hebben meeste detail-lijnen?

Filed under: Mijn Spiek Query Lib — wig @ 2:08 pm

sah = documentheaders
sal = documentlijnen
cus= customers

hoofding en detailijnen zijn type I invoice, D Delivery, O order.

Welke levering van welke klant heeft hoeveel details?

SELECT sah_code, cus_id, count( sah_code )
FROM sah, sal
WHERE sah_type = “D”
AND sah.sah_id = sal.sah_id
GROUP BY sah.sah_code

Welke levering van welke klant heeft veel details, in dalende volgorde?

SELECT sah_code, cus_id, count( sah_code ) AS teller
FROM sah, sal
WHERE sah_type = “D”
AND sah.sah_id = sal.sah_id
GROUP BY sah_code
ORDER BY teller DESC

Welke levering van welke klant heeft meeste details?

SELECT sah_code, cus_id, count( sah_code ) AS teller
FROM sah, sal
WHERE sah_type = “D”
AND sah.sah_id = sal.sah_id
GROUP BY sah_code
ORDER BY teller DESC
LIMIT 0,1

Powered by WordPress