I'm not sure how to describe the question, but I'm trying to give suggestions on what codes to attribute to tariffs. I'm doing this in Oracle.
Here's my database structure:
CODE (
CODEID *PK NCHAR(10)
)
CODETARIFF (
TARIFFNO NCHAR(15) *PK *FK
CODEID NCHAR(10) *PK *FK
)
TARIFF (
TARIFFNO NCHAR(15) *PK
)
So I'm trying to logically make templates for what codes should be assigned to tariffs. I'm imagining showing something along the lines of: "6 tariffs also have these 2 codes associated with them"
I tried this, but the counts that are returned for each of the codes aren't really showing a template, they only really show incidences of when that one code appears with the two I've specified.
SELECT COUNT(*), CodeID
FROM CodeTariff
INNER JOIN (
SELECT TariffNo, COUNT(*)
FROM CodeTariff
WHERE CodeID IN ('ABC', 'DEF')
GROUP BY TariffNo
HAVING COUNT(*) > 1) SQ
ON CodeTariff.TariffNo = SQ.TariffNo
WHERE CodeID NOT IN ('ABC', 'DEF')
GROUP BY CodeTariff.CodeID
ORDER BY COUNT(*) DESC;
Sorry if this is confusing.
I don't know if this is even possible, but I'm looking for output like this:
Data: TariffCode
TariffNo CodeID
1111 ABC
1111 DEF
2222 ABC
2222 DEF
2222 GHI
2222 JKL
3333 ABC
3333 DEF
3333 GHI
3333 JKL
Output: (when given tariff 1111)
CodesToAdd Count
GHI, JKL 2
So that I can display:
2 other tariffs have the codes GHI and JKL associated with them. Would you like to add these codes to tariff 1111?