問候並感謝您關注我的問題,希望您能提供一些見解或方向。多個表格之間的條件查詢
我有三個表(基本上):'value_meta','value'和'values_visibility'。該架構如下:
TABLE 'value_meta'
COMMENT: contains a list of different values, each referencing a different 'value' table
int id PK
tinyint value1 FK to value1.value
tinyint value2 FK to value2.value
tinyint value3 FK to value3.value
...
TABLE 'value'
COMMENT: there are different value tables (for example, if it were for user profile data, there would be a value table for "occupation", "body type", and/or "education level"
tinyint id PK
varchar(255) value
TABLE 'value_visibility'
COMMENT: one value visibility entry per value[n] in the 'value_meta' table, each a boolean value. If 1, the coding query will return the value as rerefenced in 'value[n]' table. if 0, return null
int id PK
BOOLEAN 'value1_visibility'
BOOLEAN 'value2_visibility'
BOOLEAN 'value3_visibility'
....
我想要做的是創造一個合適的MySQL查詢,以檢查「爲‘value_meta’每個‘值’,如果‘value_visibility’對應的值項爲1,顯示值VARCHAR。否則返回null「。通過正確的我想使其效率最高(dereived表與相關的子查詢,適當的條件和功能使用...我聽到ISNULL是壞的)。
我以前一直很擅長在大學裏直接回答問題,但是在多年沒有使用它之後,我已經變成了三根吸管,沒有一個完整的掃帚。誰能幫我?謝謝!
你從哪裏聽到'ISNULL`不好? – 2011-02-11 07:45:49