आप कोड उन पंक्तियों की संख्या गिनने का प्रयास करते हैं जहां सभी फ़ील्ड शून्य नहीं हैं। आपको उपयोग करना चाहिए is not null
बजाय सिर्फ not null
।
फ़ील्ड की संख्या गिनने के लिए, इसका उपयोग करें:
SELECT sum((listing_photo_1 IS NOT NULL) +
(listing_photo_2 IS NOT NULL) +
(listing_photo_3 IS NOT NULL) +
(listing_photo_4 IS NOT NULL) +
(listing_photo_5 IS NOT NULL) +
(listing_photo_6 IS NOT NULL) +
(listing_photo_7 IS NOT NULL) +
(listing_photo_8 IS NOT NULL)
) as total
from listings
WHERE pmpid = '$pmpid';
पंक्तियों की संख्या गिनने के लिए:
SELECT count(*) as total
from listings
WHERE listing_photo_1 IS NOT NULL AND
listing_photo_2 IS NOT NULL AND
listing_photo_3 IS NOT NULL AND
listing_photo_4 IS NOT NULL AND
listing_photo_5 IS NOT NULL AND
listing_photo_6 IS NOT NULL AND
listing_photo_7 IS NOT NULL AND
listing_photo_8 IS NOT NULL AND
pmpid = '$pmpid'";
संपादित करें:
अगर वे खाली हैं, तो इस तरह तर्क का प्रयोग करें:
SELECT sum((listing_photo_1 IS NOT NULL and listing_photo_1 <> '') +
(listing_photo_2 IS NOT NULL and listing_photo_2 <> '') +
(listing_photo_3 IS NOT NULL and listing_photo_3 <> '') +
(listing_photo_4 IS NOT NULL and listing_photo_4 <> '') +
(listing_photo_5 IS NOT NULL and listing_photo_5 <> '') +
(listing_photo_6 IS NOT NULL and listing_photo_6 <> '') +
(listing_photo_7 IS NOT NULL and listing_photo_7 <> '') +
(listing_photo_8 IS NOT NULL and listing_photo_8 <> '')
) as total
from listings
WHERE pmpid = '$pmpid';