这里我有一个查询,它返回各自条件的价格。我现在在做什么 在这里我有条件我正在检查 event_id是NULL或event_id =“某些值” ...我认为我想要获取行的数据,如果有数据存在“一些值“那么它应该仅返回那些没有”某个值“数据的数据,那么它应该检查为空。
在这里,我想查询event_id的数据
event_id是一些int因此它应该返回event_id的数据
如果(1)数据为空,则应为event_id选择数据IS NULL
我如何通过查询来做这件事?
查询1(检查event_id):
SELECT
`tpliv`.`ticket_sub_type_id` AS `ticketSubTypeId` ,
`tst`.`ticket_sub_type` AS `ticketSubType` ,
`tpliv`.`price` AS `ticketPrice` ,
`tpliv`.`tax` AS `ticketTax` ,
`tpliv`.`ticket_price_list_item_vendor_id` AS `ticketPriceListId` ,
`tpliv`.`ticket_price_list_id` AS `ticketPriceList` ,
`tpliv`.`fee` AS `ticketFee` , `tpliv`.`status` AS `status`
FROM `ticket_price_list_item_vendor` `tpliv`
JOIN `ticket_price_list` `tpl` ON tpl.ticket_price_list_id =tpliv.ticket_price_list_id
AND tpl.event_group_id = "45"
AND tpl.vendor_id = "442"
AND tpl.dinner_category_id IS NULL
AND tpl.status =1
AND tpl.event_id = "39152"
AND tpl.seat_section_id IS NULL
AND tpl.vendor_sub_group_id IS NULL
AND tpl.vip_seat_id IS NULL
AND tpl.seat_block_section_id IS NULL
AND tpl.is_upsale IS NULL
JOIN `ticket_sub_types` `tst` ON tst.ticket_sub_type_id = tpliv.ticket_sub_type_id
AND tst.status =1
JOIN `ticket_sub_type_vendor` `tstv` ON tstv.ticket_sub_type_id=tst.ticket_sub_type_id
AND tstv.status =1
LIMIT 0 , 30
查询2(检查event_id是否为空):
SELECT
`tpliv`.`ticket_sub_type_id` AS `ticketSubTypeId` ,
`tst`.`ticket_sub_type` AS `ticketSubType` ,
`tpliv`.`price` AS `ticketPrice` ,
`tpliv`.`tax` AS `ticketTax` ,
`tpliv`.`ticket_price_list_item_vendor_id` AS `ticketPriceListId` ,
`tpliv`.`ticket_price_list_id` AS `ticketPriceList` ,
`tpliv`.`fee` AS `ticketFee` , `tpliv`.`status` AS `status`
FROM `ticket_price_list_item_vendor` `tpliv`
JOIN `ticket_price_list` `tpl` ON tpl.ticket_price_list_id =tpliv.ticket_price_list_id
AND tpl.event_group_id = "45"
AND tpl.vendor_id = "442"
AND tpl.dinner_category_id IS NULL
AND tpl.status =1
AND tpl.event_id IS NULL
AND tpl.seat_section_id IS NULL
AND tpl.vendor_sub_group_id IS NULL
AND tpl.vip_seat_id IS NULL
AND tpl.seat_block_section_id IS NULL
AND tpl.is_upsale IS NULL
JOIN `ticket_sub_types` `tst` ON tst.ticket_sub_type_id = tpliv.ticket_sub_type_id
AND tst.status =1
JOIN `ticket_sub_type_vendor` `tstv` ON tstv.ticket_sub_type_id=tst.ticket_sub_type_id
AND tstv.status =1
LIMIT 0 , 30
所以我想做的是,如果返回数据为null,则执行查询1,然后执行查询并检索数据。
是否可以在一个查询中处理这些查询?
我想在一个查询中结合这两个查询....以用于以下场景
在第一个查询中,如果我获取数据(非空),我不必检查第二个查询
如果我在第一个查询中获取数据为null,那么应该从第二个查询中返回数据......
我想结合两个查询并进行一次查询
真实场景(为什么我不能使用(event_id IS NULL或event_id =“soem value”))
如果对于“某个event_id”,我会在返回数据中获得3行
对于event_id IS NULL我得到2行......
在这种情况下,我只想要3行带有“某个事件ID”并且我不需要其他数据......
如果对于“some event_id”我只获得空数据然后我想使用查询2来检索数据..