在 where 子句中使用日期函数进行 Codeigniter 查询

盟友比特波

我正在尝试将以下 SQL 查询转换为 Codeigniter 格式。

SELECT tb.pickup_trip_location,
   tb.drop_trip_location,
   CONCAT_WS(' ', tp.firstname, tp.lastname) AS passenger_name, 
   tb.tkt_passenger_id_no AS tkt_passenger_id_no,
   tb.trip_id_no AS trip_id_no,
   tb.id_no AS booking_id_no,
   DATE_FORMAT(tb.booking_date, '%m/%d/%Y %h:%i %p') as booking_date,
   DATE_FORMAT(tb.date, '%b %e %Y %T') as booking_time,
   tr.name AS route_name,
   tb.request_facilities AS request_facilities,
   tb.price AS price,
   tb.total_seat AS quantity,
   tb.discount AS discount,
   tb.seat_numbers AS seat_serial,
   tb.adult,
   tb.child,
   tb.special,
   tb.booking_type,
   tb.trip_route_id,
   tp.nid,
   tp.phone AS phone,
   tb.payment_status,
   fr.owner,
   fr.reg_no,
   tras.`assign_time` AS assign_time
   from tkt_booking AS tb
   join tkt_passenger AS tp ON tb.tkt_passenger_id_no = tp.id_no
   join trip_route AS tr ON tr.id = tb.trip_route_id
   join trip_assign AS tras ON tras.trip = tb.trip_id_no
   join fleet_registration AS fr ON fr.id = tb.fleet_id
   where tb.id_no = "$booking_id_no" AND
   DATE(tb.booking_date) = DATE(tras.`assign_time`)

我设法编写了以下代码,但它没有返回任何数据

return $this->db->select("
tb.pickup_trip_location,
    tb.drop_trip_location,
    CONCAT_WS(' ', tp.firstname, tp.lastname) AS passenger_name, 
    tb.tkt_passenger_id_no AS tkt_passenger_id_no,
    tb.trip_id_no AS trip_id_no,
    tb.id_no AS booking_id_no,
    DATE_FORMAT(tb.booking_date, '%m/%d/%Y %h:%i %p') as booking_date,
    DATE_FORMAT(tb.date, '%b %e %Y %T') as booking_time,
    tr.name AS route_name,
    tb.request_facilities AS request_facilities,
    tb.price AS price,
    tb.total_seat AS quantity,
    tb.discount AS discount,
    tb.seat_numbers AS seat_serial,
    tb.adult,
    tb.child,
    tb.special,
    tb.booking_type,
    tb.trip_route_id,
    tp.nid,
    tp.phone AS phone,
    tb.payment_status,
    fr.owner,
    fr.reg_no,
    tras.`assign_time` AS assign_time
")
->from('tkt_booking AS tb')
->join('tkt_passenger AS tp', 'tb.tkt_passenger_id_no = tp.id_no' ,'full')
->join('trip_route AS tr', 'tr.id = tb.trip_route_id','full')
->join('trip_assign AS tras', 'tras.trip = tb.trip_id_no','full')
->join('fleet_registration AS fr', 'fr.id = tb.fleet_id','full')
->where('tb.id_no', $booking_id_no)
->where(DATE(tb.booking_date),DATE(tras.assign_time))
->get()
->row();

问题在于以下行 ->where(Dat(tb.booking_date),DATE(tras.assign_time)) 因为当我将其注释掉时,我得到了一些数据

请帮忙

达姆

$this->db->where() 接受可选的第三个参数。如果您将其设置为 FALSE,则 CodeIgniter 将不会尝试保护您的字段或表名称。来源

因此,将您的代码更改为以下

$this->where('DATE(tb.booking_date)','DATE(tras.assign_time)', false)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在 where 子句中使用当前日期进行 Hive 选择查询

在where子句中使用AVG函数和DATEADD进行嵌套查询

CodeIgniter 中的 MySQL 更新查询使用 where in

codeigniter 在 where 子句中使用 concat regex

在where子句中使用子查询从表中选择第二高的日期

在WHERE子句中使用OR进行慢速JOIN查询-缺少可能的索引?

在WHERE子句中使用DecryptByKey进行SQL参数化查询(VB.Net前端)

在以下查询中,如何在where子句中使用“ group”进行比较?

在where子句中使用每个子查询在SQL Server中进行计数

限制WHERE子句中使用COUNT(*)函数作为子查询返回的行数

在查询 where 子句中使用复杂的情况

在SQL查询的'WHERE'子句中的'SELECT'中使用'IF'的结果

休眠-无法在where子句中使用UserType执行查询

如何在openquery where子句中使用子查询

在 where 子句中使用子查询分解结果

在where子句中使用like命名查询

TimescaleDB中gapfill的WHERE子句中使用子查询

优化在WHERE子句中使用算术运算的查询

sql在where子句中使用查询别名

在Include语句中使用Where子句的Linq查询

在组By或where子句中使用子查询SQL Server

在动态where子句中使用子查询

在 where 子句中使用子查询更新语句

如何在peewee的where子句中使用子查询?

在MySQL的where子句中使用多个表更新查询

在PostgreSQL的子查询的WHERE子句中使用别名

在 where 子句中使用可变参数查询 SQL

在where语句中使用子查询进行查询

使用Codeigniter的WHERE子句中的未知列