草庐IT

mysql - 从有条件的两个表中选择 concat

我有两个表mutation和reference如下:##Mutationmysql>select*frommutationlimit10;+------+------+------+------+-----------+|pos|ref|alt|name|alt_codon|+------+------+------+------+-----------+|6|C|T|ND1|NULL||10|T|C|ND1|NULL||2799|A|G|ND1|NULL||2808|C|T|ND1|NULL||2825|T|C|ND1|NULL||2847|A|G|ND1|NULL|##Refere

mysql - 用几个 LEFT JOIN 查询,没有得到想要的结果

这是一个sqlfiddle谁能告诉我如何使用LEFTJOIN获得此输出?notification_recipientpm_sendermsgmodification_page_idPeterTomHelloNULLnotification_recipientpm_sendermsgmodification_page_idPeterNULLNULL2这是我试过的查询:SELECTu.nameASnotification_recipient,us.nameASpm_sender,p.msg,um.page_idASmodification_page_idFROMnotificationnL

MySQL:在一个语句中连接多个表

我有以下数据库结构/层次结构:表格product_type:id,name,....表格产品:id,parent_id,name,...parent_id:是product_typeid表树节点:id,parent_id,name,type它是一个树状层次结构(根有n个子节点)层次结构的级别数未知。coltype的值为"CATEGORY"或"GROUP",这意味着,我有2棵树:类别:TreeNode1sub1.1sub.1.1.1sub.1.1.2....sub1.2sub.1.2.1sub.1.2.2....TreeNode2sub2.1sub.2.1.1sub.2.1.2....s

php - Packet和N-SubPacket Sql查询(类目和N子类同)

我正在制作数据包类型系统在我的数据包表中,父数据包(id是主键)及其N-Sub数据包在(parent_id)被存储,下面是我的表结构:Packet_tableid|packet_name|parent_id|------------------------------1|01|02|02|03|03|14|04|15|05|16|06|47|07|48|08|39|09|510|010|2........................soonandonwithNpacketsinsametable下面是我尝试过的但它没有得到idN子数据包的详细信息:SELECTp.`packet_n

mysql - 将表连接到自身非常慢

我有一个可以连接到自身的表。我想连接它两次。这是架构:CREATETABLE`route_connections`(`id`int(11)NOTNULLAUTO_INCREMENT,`from_route_iid`int(11)NOTNULL,`from_service_id`varchar(100)NOTNULL,`to_route_iid`int(11)NOTNULL,`to_service_id`varchar(100)NOTNULL,PRIMARYKEY(`id`),KEY`to_route`(`to_route_iid`),KEY`from_route`(`from_rout

mysql - 如果在 UNION ALL 查询中找不到任何行,则返回默认值

场景我有一个由此question开发的查询,优化的一部分是创建一个用于为用户和销售生成统计信息的MySqlView,问题是当SELECT行之一没有结果时,它会从结果表。问题如果没有找到任何SELECT的行,如何告诉MySql设置默认值(例如0)?代码这是创建View的代码CREATEORREPLACEVIEWuser_eventsASSELECT'Completeprofiles'AStype,created_atFROMusersWHEREcompleted_registration=1UNIONALLSELECT'Incompleteprofiles',created_atFROM

mysql - 内部 JOIN 返回重复行

我有以下表结构,每个表中都包含了主键和外键:CREATETABLE`Table1`(`Table1_ID`int(6),`Table2_FK`int(6),**OtherFields***)CREATETABLE`Table2`(`Table2_ID`int(6),`Table3_FK`int(11),**OtherFields***)CREATETABLE`Table3`(`Table3_ID`int(6),`Table2_FK`int(11),**OtherFields***)CREATETABLE`Table4`(`Table4_ID`int(6),`Table3_FK`int(

mysql - SQL 连接两个 SELECT 语句 - 相当简单

我正在尝试将两个查询结果组合成如下所示的输出:datetime|BC|AC----------------------sun|1.0|0.9通过位于下方的sql调用(在MySQL中)。我可以正确地使单个语句查询,但组合连接不起作用。有什么建议么?谢谢!对格式感到抱歉。SELECTz.datetime,(z.w_1+z.w_2+z.w_3)as'BC',(b.w_1+b.w_2+b.w_3)as'AC'(FROMmonitor_dataaWHEREmon_id="siteA"ANDdatetime>"2015-04-0204:30:00"ANDdatetime"2015-04-0204:

mysql - 如何在 Controller 中使用 join 和 whereNotIn 在 Laravel 5 中构建 SQL 查询?

我需要在LaravelController中构建以下查询。查询:select*fromtable2whereidnotin(selecttable2.idfromtable2innerjointable1ontable2.id=table1.id)我这样做了:$cond=DB::table('table2')->whereNotIn('id',function($query){$query->select(DB::raw('table2.id'))->from('table2innerjointable1ontable2.id=table1.id');})->get();请帮帮我提前致

mysql查询获取id不同列的记录

以下是我的表结构的详细信息。表结构“部门”:id|department1|Department12|Department23|Department34|Department4表结构“custom_forms_departments”:id|form_id|department_id|enduser_to_department|department_to_enduser1|5|1|Y|N2|6|1|N|Y3|8|2|Y|Y4|7|3|N|Y5|4|3|Y|N6|2|4|N|N结果应返回department_id,其在同一行或不同行中的字段“enduser_to_department”和“