join

How to combine the results of two queries?

大憨熊 提交于 2021-01-29 08:33:37
问题 I created a procedure that has two selects, I want to join the result of these two selects in one. This is my procedure CREATE PROCEDURE spConsultarVendas @nomeUsuario nvarchar(60), @dataEmissao datetime, @dataSaida datetime AS BEGIN SELECT NF.ID, NF.NaturezaOperacao, NF.DataEmissao, NF.ValorTotal FROM NotaFiscal AS NF INNER JOIN Venda AS V ON NF.ID_Venda = V.ID INNER JOIN Usuario AS U ON V.ID_UsuarioComissao1 = U.ID WHERE U.Descricao = @nomeUsuario AND (NF.DataEmissao >= @dataEmissao AND NF

Select entries that fulfil requirements laid out by dynamic table

爷,独闯天下 提交于 2021-01-29 08:18:54
问题 I'm attempting to do a keyword search which requires all conditions to be met for a result to be shown. I've created a method of making a custom table from a string which stores all of the keywords which are currently required for this search. I've been able to get it to happen for 'or' using the following dbo.MultipleTextSearchValuesOR - Is used to make the table of keywords select Title from vwIncidentSearchView inner join dbo.MultipleTextSearchValuesOR('Testing|Check') on Title Like id

Keep zero values with GROUP BY and SUM in mysql

旧街凉风 提交于 2021-01-29 05:23:04
问题 I have two tables career_types and bookings career_types id | name 1 | foo 2 | bar 3 | baz bookings id | career_type_id | details 1 | 1 | foo 2 | 1 | bar 3 | 2 | baz My bookings table has a lot of entries for all career types except career_types.id of 3. I want a query that will list all my career_types.name's and how many each booking has, and in the case of career_types.id = 1 where there are no bookings for it. I want to return 0. So far I've been trying variations of SELECT career_types

Remove duplicates on MySQL JOIN query on JSON_ARRAYAGG with INNER JOIN

会有一股神秘感。 提交于 2021-01-29 05:22:57
问题 I have an app with users; the users can create bookmarks, and each bookmark can have multiple tags. So, if I'm not mistaken in the notation: user =* bookmark *=* tag Now I try to retrieve all users with a JSON array with the tags they used. I need a JSON array because I may need to retrieve the name or other data from the tags or the bookmarks: SELECT `user`.id, JSON_ARRAYAGG( JSON_OBJECT( "id", tag.id ) ) AS tags, JSON_ARRAYAGG( JSON_OBJECT( "id", bookmark.id ) ) AS bookmarks FROM tag INNER

Replace comparison to scalar subquery by inner join or left/right join

夙愿已清 提交于 2021-01-29 04:29:10
问题 I need to write this query using inner joins or right/left joins but I don't know how to start: select * from radicados where asignado = (select estudianteid from estudiantes where usuario = (select usuarioid from usuarios where nombre = $nombre_usuario)) But I don't know how to do the same with joins. I think this must be something like: select * from radicados inner join usuarios on usuarioid=usuario 回答1: It appears you want something like this: select radicados.* from radicados join

Replace comparison to scalar subquery by inner join or left/right join

╄→гoц情女王★ 提交于 2021-01-29 04:22:07
问题 I need to write this query using inner joins or right/left joins but I don't know how to start: select * from radicados where asignado = (select estudianteid from estudiantes where usuario = (select usuarioid from usuarios where nombre = $nombre_usuario)) But I don't know how to do the same with joins. I think this must be something like: select * from radicados inner join usuarios on usuarioid=usuario 回答1: It appears you want something like this: select radicados.* from radicados join

Self Joining in R

淺唱寂寞╮ 提交于 2021-01-28 21:06:13
问题 Here is a sample tibble: test <- tibble(a = c("dd1","dd2","dd3","dd4","dd5"), name = c("a", "b", "c", "d", "e"), b = c("dd3","dd4","dd1","dd5","dd2")) And I want to add a new column b_name as self-join to test using: dplyr::inner_join(test, test, by = c("a" = "b")) My table is way to large (2.7M rows with 4 columns) and I get the following error: Error: std::bad_alloc Please advise how to do it right / best practice. My final goal is to get the following structure: a name b b_name dd1 a dd3 c

Postgresql: count records by time intervals

与世无争的帅哥 提交于 2021-01-28 19:31:54
问题 I am trying to use the following SQL statement with postgresql to generate some report: WITH GRID AS ( SELECT START_TIME, LEAD(START_TIME) OVER (ORDER BY START_TIME) AS END_TIME FROM ( SELECT GENERATE_SERIES('2015-08-01 12:00:00', '2015-09-01 12:00:00', INTERVAL '1 day') AS START_TIME FROM MY_TABLE ) x ) SELECT START_TIME, COUNT(MY_TABLE._ID) AS COUNT FROM GRID LEFT JOIN MY_TABLE ON MY_TABLE.CREATED >= GRID.START_TIME AND MY_TABLE.CREATED < GRID.END_TIME WHERE MY_TABLE.COMPANY_ID = '1001' AND

How can I Create a Multi-Value CrossTab Query in Access 2013?

走远了吗. 提交于 2021-01-28 19:04:06
问题 My Issue I'm working in Access 2013. I have a set of data that needs broken down based on two fields (best done with a crosstab query). My issue is, I need to show the SUM and the COUNT of each 'Value' ([Amt Total] field) -- and unfortunately Access has yet to allow multi-value crosstab queries. For reference purposes if someone is searching online with similar issues - the resulting error if you try to add multiple 'Value' fields in Access: To create a crosstab query, you must specify one or

efficient conditional cross join in data table

笑着哭i 提交于 2021-01-28 14:11:42
问题 EDITED (Sorry, I modified the code, it had an error that prevented reproduction.) I am trying to efficiently merge with a condition. The way I am doing it now is to cross-join (which I want to preserve) except I have one condition for a subset of the columns. Cross join function (from here) CJ.table.1 <- function(X,Y) setkey(X[,c(k=1,.SD)],k)[Y[,c(k=1,.SD)],allow.cartesian=TRUE][,k:=NULL] set.seed(1) #generate data x = data.table(t=rep(1:10,2), z=sample(1:10,20,replace=T)) x2 = data.table