Questions tagged «subquery»

“子查询”是模糊的SQL术语,用于描述查询中何时有多个“ SELECT”语句,或何时用于数据操作语言(DML)语句(即:DELETE,UPDATE,INSERT,MERGE)。子查询的SELECT语句始终位于方括号/括号内。

2
SQL LEFT JOIN子查询别名
我正在运行此SQL查询: SELECT wp_woocommerce_order_items.order_id As No_Commande FROM wp_woocommerce_order_items LEFT JOIN ( SELECT meta_value As Prenom FROM wp_postmeta WHERE meta_key = '_shipping_first_name' ) AS a ON wp_woocommerce_order_items.order_id = a.post_id WHERE wp_woocommerce_order_items.order_id =2198 我得到这个错误: #1054-'on子句'中的未知列'a.post_id'。 我认为我的代码很简单,但是我做错了。我究竟做错了什么?

4
如何在MySQL中从选择中删除?
此代码不适用于MySQL 5.0,如何重写使其正常工作 DELETE FROM posts where id=(SELECT id FROM posts GROUP BY id HAVING ( COUNT(id) > 1 )) 我想删除没有唯一ID的列。我会在大多数情况下添加唯一的一个ID(我尝试了in语法,它也不起作用)。

9
MySQL DELETE FROM以子查询为条件
我试图做这样的查询: DELETE FROM term_hierarchy AS th WHERE th.parent = 1015 AND th.tid IN ( SELECT DISTINCT(th1.tid) FROM term_hierarchy AS th1 INNER JOIN term_hierarchy AS th2 ON (th1.tid = th2.tid AND th2.parent != 1015) WHERE th1.parent = 1015 ); 您可能会说,如果同一提示有其他父母,我想删除1015的父母关系。但是,这产生了一个语法错误: You have an error in your SQL syntax; check the manual …

5
ActiveRecord中的子查询
使用SQL,我可以轻松地执行这样的子查询 User.where(:id => Account.where(..).select(:user_id)) 这将产生: SELECT * FROM users WHERE id IN (SELECT user_id FROM accounts WHERE ..) 如何使用Rails的3 activerecord / arel / meta_where做到这一点? 我确实需要/想要真正的子查询,没有红宝石的解决方法(使用几个查询)。

5
如何在select子句中使用Post in子句(如SQL Server)在Post子句中进行Postgresql子查询?
我正在尝试在postgresql上编写以下查询: select name, author_id, count(1), (select count(1) from names as n2 where n2.id = n1.id and t2.author_id = t1.author_id ) from names as n1 group by name, author_id 这当然可以在Microsoft SQL Server上使用,但在postegresql上则根本不可用。我读了一点文档,似乎可以将其重写为: select name, author_id, count(1), total from names as n1, (select count(1) as total from names as n2 where n2.id …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.