假设我们在数据库中有以下集合:
db.documents.insert([{'name': 'A'}, {'name': 'B'}, {'name': 'C'}])
db.fragments.insert([{'value:': 'A1', doc_name: 'A'}, {'value:': 'A2', doc_name: 'A'},
{'value:': 'B1', doc_name: 'B'}, {'value:': 'B2', doc_name: 'B'},
{'value:': 'C1', doc_name: 'C'}, {'value:': 'C2', doc_name: 'C'}])
Run Code Online (Sandbox Code Playgroud)
其中documents
collection存储文档的名称(以及本示例中省略的其他内容),fragments
集合引用doc_name
与该片段相关的文档.
现在,如果我只想考虑一部分文件
> db.documents.find().limit(2)
{ "_id" : ObjectId("52d1a3bf49da25160ad6f076"), "name" : "A" }
{ "_id" : ObjectId("52d1a3bf49da25160ad6f077"), "name" : "B" }
Run Code Online (Sandbox Code Playgroud)
那我怎么能看到与这些选定文件相关联的片段,所以我会得到
{ "_id" : ObjectId("52d1a3bf49da25160ad6f079"), "value:" : "A1", "doc_name" : "A" }
{ "_id" : ObjectId("52d1a3bf49da25160ad6f07a"), "value:" : "A2", "doc_name" : "A" } …
Run Code Online (Sandbox Code Playgroud) 我想知道在避免重复的同时创建列表的最佳方法是什么.
我在mysql中有一些数据包含产品类型.
例如:
id ------- category
1 -------- food, drink, vege
2 -------- food, drink
3 -------- vege, baby goods
4 -------- fish
Run Code Online (Sandbox Code Playgroud)
我瞄准的输出是:
['food','drink','vege','baby goods','fish']
Run Code Online (Sandbox Code Playgroud)
(请注意订单对我来说无关紧要)
数据集有超过40,000条记录,因此手动检查肯定不是一种选择......
如果你能给我一个说明或建议,我将不胜感激.
我在sqlite查询中使用like
关键字时面临一些奇怪的问题inner join
.
我想获取category_code上的记录,因为category_code在两个表中以不同的字符串格式保存.所以我写下面的查询,但没有输出.
select categories.category_code, services.* from categories join services on services.category_code like '%' + categories.category_code + '%' where services.country_code like '%IN%'
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
在这个主题的任何地方都很难搜索......基本上,我从两个表中选择,每个表都有JOIN
子句.如果我按每个表分开查询,两者都工作正常...下面看起来逻辑上对我来说..但它给了我一个错误:
Error Code: 1054. Unknown column 'catalogue.ID' in 'on clause' 0.000 sec
Run Code Online (Sandbox Code Playgroud)
这个查询是否可行,我在这里缺少什么?
SELECT `catalogue`.`ID`,`catalogue`.`Catalogue`,`catalogue`.`Artist`,`catalogue`.`Title`, `catalogue`.`Street_Date`,
`label`.`label_name` as `label`,
`format`.`format_name` as `Format`,
`schedule`.designer,`schedule`.`MO`,
`packtype`.`description` as `Package`,
`manufacturer`.`description` as `Manufacturer`
FROM `catalogue`, `manufacture`
LEFT JOIN `schedule` ON (`schedule`.`cat_id` = `catalogue`.`ID`)
LEFT JOIN `label` ON (`catalogue`.`label` = `label`.`Lbl_ID`)
LEFT JOIN `format` ON (`catalogue`.`format` = `format`.`Fmt_ID`)
LEFT JOIN `packtype` ON `packtype`.`pack_id` = `manufacture`.`pack_id`
LEFT JOIN `manufacturer` ON `manufacturer`.`man_id` = `manufacture`.`manuf`
WHERE `catalogue`.`Street_Date`="2014-03-17" and `manufacture`.`cat_id` = `catalogue`.`ID`
ORDER BY `catalogue`.`Catalogue` asc LIMIT …
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行一个报告来显示过去90天内所有日期的列表,然后将其加入另一个表中,该表在一列中有日期,而另一列中有补充数据.以下是我获取范围内所有日期的方法:
select trunc(sysdate-90) + rownum -1 from all_objects where rownum <=90
Run Code Online (Sandbox Code Playgroud)
问题是在日期将其加入另一个表.如果我跑:
select trunc(sysdate-90) + rownum -1, t.col2 from all_objects
left join (select date, col2 from table) t on trunc(sysdate-90) + rownum -1 = t.date
where rownum <=90
Run Code Online (Sandbox Code Playgroud)
然后它只显示t.col2中的第一条记录,表示日期范围内的所有值.如何正确加入这两个表?
谢谢
我有2个表,每个表都有一列MNR
.我想和他们一起加入这个专栏.
以下两个SQL语句失败.最后一个显示我的日期格式正在运行(更改了会话格式).DB是Oracle.
有人可以告诉我我做错了什么吗?我怎么称呼这个加入?
// fails
select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR
from INFOR.RELFBR as a, INFOR.RELXDB as b
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10')
and (a.CREATEDATE >= '01.01.2014 00:00:00')
order by a.CREATEDATE
// fails as well
select a.CREATEDATE, a.BELEGNRRECH, a.MNR, a.UTNR, a.KTXT, b.ANR
from INFOR.RELFBR as a, INFOR.RELXDB as b
where (a.SAINT = '90') and (a.MNR = b.MNR) and (b.SAINT = '10')
order by a.CREATEDATE
// all fine
select CREATEDATE, …
Run Code Online (Sandbox Code Playgroud) list = [8,4,3,2,5]
Run Code Online (Sandbox Code Playgroud)
有没有办法连接两个不使用切片的元素
print ' '.join(list[0:3]) #would print out the numbers in between
Run Code Online (Sandbox Code Playgroud)
如果我想打印那些特定元素怎么办?
我有2个如下表:
Table 1
---------
1
2
3
Table 2
--------
A
B
C
Run Code Online (Sandbox Code Playgroud)
我如何加入以获得如下输出:
Output
---------
1 A
1 B
1 C
2 A
2 B
2 C
3 A
3 B
3 C
Run Code Online (Sandbox Code Playgroud) 我为学生计划打印输出创建了这个连接语句,我是sql和php的新手,无法弄清楚我做错了什么.如果有人可以帮助我会非常感激..提前感谢...(如果这是一个非常基本的问题,我很抱歉)...
mysql_select_db($database_newconn, $newconn);
$query_Recordset1 = "SELECT a.student_id AS "Student ID", f.name AS "Course Name", g.name AS "Lesson Name", g.date AS "Lesson Date", g.start_time AS "Lesson Start Time", g.end_time AS "Lesson End Time", CONCAT( h.first_name,' ', h.last_name) AS "Lesson Tutor" FROM student_table a JOIN enrollement_schedule_table b ON(a.id = b.student_id) JOIN course_table f ON(f.id = b.course_id) JOIN student_attendance_slot_table c ON(c.student_id = a.id) JOIN lesson_table g ON(g.id = c.lesson_id) JOIN tutor_table d ON(d.id = g.tutor_id) JOIN staff_table h ON(h.id = d.staff_id)";
$Recordset1 = …
Run Code Online (Sandbox Code Playgroud) P_Id Catid Score ArtId PostId PhaseId UserId Deleted ModDate
26 1 20 57 5 18 8 0 2014-03-29
27 2 18 57 5 18 8 0 2014-03-29
28 3 7 57 5 18 8 0 2014-03-29
29 4 5 57 5 18 8 0 2014-03-29
30 5 20 57 5 18 8 0 2014-03-29
31 1 12 57 1 18 9 0 2014-03-29
32 2 15 57 1 18 9 0 2014-03-29
33 3 15 57 1 18 9 0 …
Run Code Online (Sandbox Code Playgroud)