使用 Zend 框架进行 UNION 和 NOT IN Mysql 操作

发布于 2024-09-28 20:45:54 字数 1091 浏览 9 评论 0原文

我需要在 Zend 中执行以下 mysql 查询;我不是 Zend 框架的专家,

SELECT  `optionride`.`featureoption_id`,
`optionride`.`featureoptionride_id`,`foption`.`featureoptionblock_id`,

`foption`.`labelname`,`optionride`.`value` FROM 
`engine4_ride_featureoptionrides` AS `optionride` 
LEFT JOIN `engine4_ride_featureoptions` AS `foption` 
ON foption.featureoption_id = optionride.featureoption_id 
WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )

UNION

SELECT `foption`.`featureoption_id`,  null as    
`featureoptionride_id`,`foption`.`featureoptionblock_id`,
`foption`.`labelname`,null as `value` FROM `engine4_ride_featureoptions` AS `foption`
WHERE (foption.featureoptiontab_id= '2' ) AND `foption`.`featureoption_id` NOT IN
(
   SELECT `optionride`.`featureoptionride_id` FROM `engine4_ride_featureoptionrides`   
   AS `optionride` 
   LEFT JOIN `engine4_ride_featureoptions` AS `foption` ON 
   foption.featureoption_id   =      optionride.featureoption_id 
  WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )
 )

任何人都可以帮助我。

I need to execute the following mysql query in Zend;I am not an excpert with Zend framework

SELECT  `optionride`.`featureoption_id`,
`optionride`.`featureoptionride_id`,`foption`.`featureoptionblock_id`,

`foption`.`labelname`,`optionride`.`value` FROM 
`engine4_ride_featureoptionrides` AS `optionride` 
LEFT JOIN `engine4_ride_featureoptions` AS `foption` 
ON foption.featureoption_id = optionride.featureoption_id 
WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )

UNION

SELECT `foption`.`featureoption_id`,  null as    
`featureoptionride_id`,`foption`.`featureoptionblock_id`,
`foption`.`labelname`,null as `value` FROM `engine4_ride_featureoptions` AS `foption`
WHERE (foption.featureoptiontab_id= '2' ) AND `foption`.`featureoption_id` NOT IN
(
   SELECT `optionride`.`featureoptionride_id` FROM `engine4_ride_featureoptionrides`   
   AS `optionride` 
   LEFT JOIN `engine4_ride_featureoptions` AS `foption` ON 
   foption.featureoption_id   =      optionride.featureoption_id 
  WHERE (optionride.ride_id = '1' ) AND (foption.featureoptiontab_id= '2' )
 )

Anybody can help me please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

近箐 2024-10-05 20:45:54

您可以将所有查询放在 $db->fetch() 中。

您也可以使用 $db->select()->union(array($sql1, $sql2)),其中 $sql1, $sql2 可以是 $db->select() 或字符串("select...")。

对于NOT IN,您可以使用$db->where('someField NOT IN (?)', array());

You can put all your query asis in the $db->fetch().

Also you can use $db->select()->union(array($sql1, $sql2)), where $sql1, $sql2 can be $db->select() or a string ("select...").

For the NOT IN you can use $db->where('someField NOT IN (?)', array());

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文