SQL如何计算空值

时间:2016-03-11 03:18:34

标签: sql

我陷入了死胡同,希望能在这里得到一些启示。

我必须返回一张表格,告诉我有关出租车预订的信息。 我必须显示驱动程序编号,总客户出价,成功的客户出价和不成功的客户出价。

在预订表下,如果driver和distance_travelled的值为null,则表示预订不成功。我的代码下面给我一个空表,我不太明白为什么。

    select Phone_Num as 'Driver Phone', 
    count(b.Booking_ID) as 'Number of bids made', 
    count(bo.driver) as 'Number of unsuccessful bids',         
    count(bo.Distance_travelled)as 'Number of successful bids'
    from driver d, bids b, booking bo
    where d.Phone_Num=b.Driver_Num and bo.Booking_ID=b.Booking_ID
    and bo.driver is null and bo.distance_travelled is not null
    group by Phone_Num;

这是我的表结构:

create table bids(
Booking_ID char(6) not null,
Driver_Num char(8) not null,
constraint bids_pk primary key (Booking_ID, Driver_Num),
constraint bids_fk1 foreign key (Booking_ID) references Booking(Booking_ID),
constraint bids_fk2 foreign key (Driver_Num) references Driver(Phone_Num));


create table booking(
Booking_ID char(6) not null primary key,
Book_Time datetime not null,
Distance_travelled double,
B_Type varchar(15) not null,
Car_Type varchar(40) not null,
commuter char(8) not null,
Driver char(8),
Pickup_location char(6) not null,
constraint booking_fk1 foreign key (Car_Type) references sd    Car_Type(Car_Type_Name),
constraint booking_fk2 foreign key (Commuter) references     commuter(Phone_Num),
constraint booking_fk3 foreign key (Driver) references driver(Phone_Num),
constraint booking_fk4 foreign key (Pickup_location) references     location(Zip_code));

create table Driver
(Phone_Num char(8) not null,
License_Num varchar(10) not null,
Bank_Account varchar(20) not null,
constraint driver_pk primary key(Phone_Num),
constraint driver_fk1 foreign key (Phone_Num) references App_User(Phone_Num));

0 个答案:

没有答案
相关问题