草庐IT

join_group

全部标签

mysql - group_concat 在 MySQL 中有多个连接

数据库架构createtable`questions`(`id`intnotnullauto_increment,`title`varchar(45)notnull,primarykey(`id`));createtable`tags`(`id`intnotnullauto_increment,`question_id`intnotnull,`name`varchar(45)notnull,primarykey(`id`));createtable`comments`(`id`intnotnullauto_increment,`question_id`intnotnull,`body`

mysql - 带有 WHERE 条件的 Postgres LEFT JOIN

我需要用where条件左连接两个表:表time_tableidridstart_dateend_date122017-07-0100:00:002018-11-0100:00:00252017-01-0100:00:002017-06-0100:00:00322018-07-0100:00:002020-11-0100:00:00表record_tableidnamedate1record12017-10-0100:00:002record22017-02-0100:00:003record32017-10-0100:00:00我需要获取给定日期范围内的所有记录。在上面的示例中,我只需

mysql - 如何在mysql中使用JOIN来显示所有不匹配的数据

我想显示2个表中的数据,并且我想显示所有表,包括不匹配的数据。我试过这个查询。SELECT*FROMstudentsLEFTJOINgradegONg.student_id=s.student_idWHEREs.student_id=9我得到的只是显示有成绩的学生,而我需要的是显示所有学生,即使他们没有任何成绩。我也试过使用innerjoin,rightjoin但结果是一样的。查询应该是什么? 最佳答案 问题是WHEREs.student_id=9,因为左表(students表)中未匹配的行,s.student_id等于null,而

sql - 文本字段上的 COUNT 和 GROUP BY 似乎很慢

我正在构建一个MySQL数据库,其中包含有关酵母物种中特殊DNA子串的条目。我的表看起来像这样:+--------------+---------+------+-----+---------+-------+|Field|Type|Null|Key|Default|Extra|+--------------+---------+------+-----+---------+-------+|species|text|YES|MUL|NULL|||region|text|YES|MUL|NULL|||gene|text|YES|MUL|NULL|||startPos|int(11)|Y

MySQL:使用 JOIN 和 GROUP_CONCAT 进行更新

这可能吗?我有2个表,客户和订单。现在我想用该客户的所有订单ID(以逗号分隔)填写Customers中的一列。我试过类似的东西,但它不起作用:UPDATEcustomersAScLEFTJOINordersASoONo.customerid=c.customeridSETc.orders=GROUP_CONCAT(DISTINCTo.orderid)我收到“群组功能的无效使用”。附言。我知道最好始终在SELECT/JOIN中动态获取GROUP_CONCAT值,但我只是想知道我是否可以通过某种方式填充此列。 最佳答案 您需要在grou

sql - MySQL - 使用 UNION ALL 和 GROUP BY 进行搜索

SELECTp.id,p.title,p.uri,'post'ASsearch_typeFROM`posts`ASpWHEREtitleLIKE"%logo%"UNIONALLSELECTp.id,p.title,p.uri,'tag'ASsearch_typeFROMpostsASpINNERJOINpost_tagsASptONpt.post_id=p.idINNERJOINtagsAStONpt.tag_id=t.idWHEREt.titleLIKE"%logo%"UNIONALLSELECTp.id,p.title,p.uri,'category'ASsearch_typeFR

php - 如何在 Zend Framework 中使用 GROUP_CONCAT?

假设我有一张table:学生______________________________________________________|id|name|school|class|______________________________________________________|1|John|ABC|C1||2|Jack|ABC|C1||3|Anna|ABC|C1||4|Peter|DEF|D1||5|Alex|ABC|C2||6|Bryan|ABC|C2||7|David|ABC|C2||8|Cristian|DEF|D1|_________________________

mysql - 使用桥接表使用 INNER JOIN 语句的正确方法

基本上我有一个带有“Product_ID”的表“Products”和带有“Sub_Category_ID”的表“Sub_Categories”。具有“Sub_Category”的产品使用桥接表“SubC_Prod_Bridge”链接,它们通过ID“Products”和“Sub_Category_ID”链接。像这样:Table:ProductsProduct_ID4Table:Sub_CategoriesSub_Category_ID5Table:SubC_Prod_BridgeProduct_IDSub_Category_ID45我知道这个问题很基础。我真正想要的是一个很好的JOIN语

php - CodeIgniter GROUP_CONCAT 并加入

我想找到一种方法将这两个表连接在一起,我能够做到,但如果它找到多个匹配的值,它会再次显示产品表中的所有内容。现在我正在尝试一起使用MySQLgroup_concat以便能够在数组的一个字段中列出所有tName但我不断收到MySQL的错误:ErrorNumber:1064YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'FROM(sp_product)LEFTOUTERJOINsp_product_typeONsp_pr

mysql - 使用 GROUP BY 删除重复项的查询

id_specific_priceid_product-------------------------------12223243536373需要删除重复项,预期结果:id_specific_priceid_product-------------------------------3273SELECT*FROMps_specific_priceWHEREid_specific_priceNOTIN(SELECTMAX(id_specific_price)FROMps_specific_priceGROUPBYid_product)有效但是DELETEFROMps_specific_