1

例如,我正在尝试使用 where 子句匹配表中多个字段中的空值

 SELECT * FROM manage_users WHERE coalesce(surname, firstname, lastname, physical_address, postal_address, telephone_number, fax_number, cell_number, email,medical_aid_fund, medical_aid_number, allergies, emergency_contatct_person, emergency_contatct_number, id_number,gender, age_on_raceday, age_groups, shirt_size, type_of_club, roag_membership_number, csa_licence_number, provinical_running_licence_number, provinical_running_canoeing_number, tsa_licence_number, licence_number, number_of_comrade_marathon_completed, number_of_two_oceans_completed,    number_of_duzi_completed, number_of_nonstop_duzi_completd,number_of_amashova_completed, 
number_of_argus_completed, number_of_947_completed, number_of_midmar_mile_completed, make_of_running_shoes, make_of_road_bike, make_of_mtb, make_of_wetsuit) is NOT NULL and id='16'

我为此使用了合并,这是正确的方法。我没有得到预期的输出。谁能帮我得到结果。这将不胜感激。

4

2 回答 2

4

COALESCE返回参数列表中的第一个非空值。因此,如果任何字段不为空,您的查询将成功,它并不要求它们全部为非空。

您可以改为使用:

SELECT * FROM manage_users WHERE CONCAT(<list of columns>) is NOT NULL and id='16'

CONCAT()与大多数普通函数一样,如果任何参数为 NULL,则返回 NULL。

要检查任何空值,请添加:

AND LEAST(<list of string columns>) != ''

这应该只是字符串列;如果在 中混合字符串和数字LEAST,它会将所有字符串转换为数字,并且任何不以数字开头的字符串都将转换为0,因此它不会进行适当的测试。

于 2013-07-30T06:47:53.163 回答
1

不接受 null 和空值的查询。它将选择提到的列在其中具有值的行。

Select * from manage_users where (surname and firstname and lastname and physical_address and postal_address) > ''
于 2013-07-30T07:50:34.140 回答