Help w/ Conditional in Select Query?
Is it possible to integrate some conditionals in a SELECT query? Here's my current working query:
Here's what I need to accomplish now:
SELECT f.fieldID, f.fieldNew, f.fieldFeatured, f.fieldSale, f.fieldTitle,
f.fieldDrillGrade, TRUNCATE(ROUND(AVG(i.itemGrade) * 2) / 2,1) AS fieldMusicGradeAvg,
g.genreName, (f.fieldSets1 + f.fieldSets2 + f.fieldSets3 + f.fieldSets4 + f.fieldSets5) AS fieldTotalSets,
SUM(i.itemTime) AS fieldTotalTime, SUM(i.itemPrice) + f.fieldDrillOnly AS fieldTotalPrice
FROM field AS f
INNER JOIN items AS i ON i.itemID IN (f.fieldMusic1, f.fieldMusic2, f.fieldMusic3, f.fieldMusic4, f.fieldMusic5)
LEFT OUTER JOIN genres AS g ON g.genreID = f.fieldGenre
WHERE f.fieldEnabled = 'Yes'
GROUP BY f.fieldTitle, f.fieldDrillGrade
ORDER BY f.fieldTitle
Some records in the "field" table may NOT be associated with records in the "items" table. If fieldMusicTitle1, fieldMusicTitle2, fieldMusicTitle3, fieldMusicTitle4, or fieldMusicTitle5 (new fields) have content -- I need the query to IGNORE the INNER JOIN with the items table.
If this conditional is true -- I also need:
* fieldMusicGradeAvg would then become the value of fieldMusicGrade (new field).
* fieldTotalTime would then become the sum of fieldTime1, fieldTime2, fieldTime3, fieldTime4, fieldTime5 (new fields).
* fieldTotalPrice would then become the sum of fieldMusicOnly and fieldDrillOnly.
Is this all even possible? Thank you for any help you can provide.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)