Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

求助:请问如何进行UNION的操作 #668

Closed
haycun opened this issue Jan 27, 2021 · 7 comments
Closed

求助:请问如何进行UNION的操作 #668

haycun opened this issue Jan 27, 2021 · 7 comments
Labels
question Further information is requested

Comments

@haycun
Copy link

haycun commented Jan 27, 2021

WithSql使用的是UNION ALL,需要进行UNION的查询操作,除了使用自己编写SQL语句的方式,应该怎么编写,谢谢

@2881099
Copy link
Collaborator

2881099 commented Jan 27, 2021

#478

@haycun
Copy link
Author

haycun commented Jan 27, 2021

那如果想生成这样的语句该如何处理

//SELECT * from (SELECT a.Id, a.Title, a.Content, a.CreateTime
//FROM ( SELECT a.Id, a.Title, a.Content, a.CreateTime
// FROM Topic a
// WHERE ((a.Title) LIKE '%xxx%') ) a) ftb
//
//UNION
//
//SELECT * from (SELECT a.Id, a.Title, a.Content, a.CreateTime
//FROM ( SELECT a.Id, a.Title, a.Content, a.CreateTime
// FROM Topic a
// WHERE ((a.Title) LIKE '%yyy%') ) a) ftb

@luoyunchong
Copy link
Collaborator

没有。

@luoyunchong luoyunchong added the question Further information is requested label Jan 27, 2021
@haycun
Copy link
Author

haycun commented Jan 27, 2021

UNION在多表查询时剔除重复行还是很实用的,是否可以考虑在后续的版本中添加上?

@2881099
Copy link
Collaborator

2881099 commented Jan 27, 2021

那如果想生成这样的语句该如何处理

//SELECT * from (SELECT a.Id, a.Title, a.Content, a.CreateTime
//FROM ( SELECT a.Id, a.Title, a.Content, a.CreateTime
// FROM Topic a
// WHERE ((a.Title) LIKE '%xxx%') ) a) ftb
//
//UNION
//
//SELECT * from (SELECT a.Id, a.Title, a.Content, a.CreateTime
//FROM ( SELECT a.Id, a.Title, a.Content, a.CreateTime
// FROM Topic a
// WHERE ((a.Title) LIKE '%yyy%') ) a) ftb

这个不是可以用 or 查询吗

@haycun
Copy link
Author

haycun commented Jan 27, 2021

写错了,我原意是多张表的情况下
//SELECT * from (SELECT a.Id, a.Title, a.Content, a.CreateTime
//FROM ( SELECT a.Id, a.Title, a.Content, a.CreateTime
// FROM TopicOne a
// WHERE ((a.Title) LIKE '%xxx%') ) a) ftb
//
//UNION
//
//SELECT * from (SELECT a.Id, a.Title, a.Content, a.CreateTime
//FROM ( SELECT a.Id, a.Title, a.Content, a.CreateTime
// FROM TopicTwo a
// WHERE ((a.Title) LIKE '%yyy%') ) a) ftb

@pjy612
Copy link

pjy612 commented Apr 29, 2021

试试那个 分表查询 同对象
.AsTable((type,oldname)=>type==typeof(T1)?"TopicOne":oldname)
.AsTable((type,oldname)=>type==typeof(T2)?"TopicTwo":oldname)

不过你这里查询条件也不一样了。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants