Posts by Sorack • 27,430 points
864 posts
-
5
votes2
answers432
viewsQ: Permutations of an integer disregarding the zeros on the left
I have the following problem: Given an input n I have to calculate the number of possible permutations with the digits that compose it. For example, if n = 123 I have 6 numbers that can be formed:…
-
1
votes2
answers127
viewsA: Doubt in Mysql query
There are some problems in your query, the two main ones are the following: What is happening is that when I run this query instead of returning me the expected returns me empty... For INSERT that…
-
0
votes2
answers45
viewsA: Content of the array is not being printed, but reference to the object
You can use method Arrays#toString: import java.util.Arrays; ... System.out.println(Arrays.toString(newArray)); Arrays#toString Returns a string representation of the Contents of the specified…
-
1
votes1
answer51
viewsA: Java array shows specific items
To get the result you want to make the following changes to your code: In the if check that the elements are equal, and if they are, skip to the next loop iteration; Add a else if check if you are…
-
5
votes1
answer2217
viewsA: How to Bring the 2 highest values of each different id - SQL
Use the function DENSE_RANK to obtain the desired result: SELECT x.id_sala, x.mensalidade FROM (SELECT *, DENSE_RANK() OVER(PARTITION BY e.id_sala ORDER BY e.mensalidade DESC) AS colocacao FROM…
-
1
votes2
answers137
viewsA: Prioritize line in sql queries
You can compare the table with itself to get the highest priority: SELECT * FROM tabela t WHERE t.prioridade = (SELECT MAX(t2.prioridade) FROM tabela t2 WHERE t2.origem = t.origem AND t2.destino =…
-
5
votes1
answer433
views -
1
votes2
answers362
viewsA: Sort Numbers and seasons correctly
The problem is that the columns numero and temporada were declared as VARCHAR, therefore it is being sorted alphabetically. To fix this problem, state it as INTEGER or carry out the ORDER BY…
-
2
votes1
answer57
viewsA: Update table so that a field has a unique value
You can create a TRIGGER that does what has been described: CREATE TRIGGER trg_jogadores_ai AFTER UPDATE ON jogadores FOR EACH ROW BEGIN IF (NEW.artilheiro = 1) THEN UPDATE jogadores SET artilheiro…
-
4
votes1
answer126
viewsQ: What is the most performative way to convert an int into the sum of its digits?
I have a certain int and would like to turn it into another that is the result of the sum of your digits in the best possible way. For example: int n = 2601; Should result in 9 since this is the…
-
3
votes1
answer240
viewsQ: What is the most performative way to convert int[] to int?
What is the most performatic way to convert the inverted positions of a array for int? For example, the following array should work in full 153 for the purpose of future calculation: int[] a = new…
-
1
votes1
answer217
viewsA: Use Datepart as Query parameter
How you want to search using the days of the week, can treat the DATEPART as a whole. In case of search for days of the week: SELECT * FROM view v WHERE DATEPART(WEEKDAY, v.data) NOT IN (7, 1) --…
-
8
votes3
answers469
viewsA: How to remove spaces from a string in Java?
I propose the following changes in the class to get the desired result (explanations in comments within the code): import java.util.Arrays; public class Diamante { private static final String[]…
-
1
votes2
answers433
viewsA: How to indicate how many equal numbers there are between two vectors?
For complementary, it can be solved using Collection with the following method: public Integer[] encontrarInterseccao(Integer[] vetor1, Integer[] vetor2) { Set<Integer> conjunto1 = new…
-
3
votes3
answers142
viewsA: Help with java arrays
You can use the Set which does not allow duplicates. Set<String> disciplinas = new HashSet<>(Arrays.asList(disciplina)); disciplina = disciplinas.toArray(new String[disciplinas.size()]);…
-
0
votes1
answer145
viewsA: Trigger without replicating data - SQL Server 2012
To TRIGGER demonstrated will only run once, regardless of the amount of records entered or changed. To change thinking of several records I suggest the following: ALTER TRIGGER…
-
1
votes2
answers1233
viewsA: Date Working Hours - SQL Server
You can create a function that increments by checking if the time is within the range: IF OBJECT_ID('dbo.adicionar_horas_uteis', 'FN') IS NULL BEGIN EXEC('CREATE FUNCTION dbo.adicionar_horas_uteis()…
-
1
votes2
answers82
viewsA: SQLSERVER compare two groups of results
You can apply the clause EXISTS as follows: SELECT e.* FROM Estoque e WHERE EXISTS(SELECT 1 FROM empresacategoria ec INNER JOIN produto p ON p.idcategoria = ec.idcategoria WHERE ec.idempresa = 1 AND…
-
0
votes5
answers833
viewsA: How to calculate the date and shift code?
First of all the best type of data for the start of the shift is TIME, after all you don’t need the part DATE of the data. Whereas the shift may start in one day and end in the other, the condition…
-
8
votes2
answers134
viewsA: Problem with return of a Java method
The mistake: Missing Return statement Or in free translation: return declaration missing It occurs when a method is declared with return and there are possibilities of this return value not being…
-
0
votes2
answers54
viewsA: Decreasing the value of two fields of a table and sorting according to the result
Use parentheses to subtract: $woes = DB::table('woeplayerrank as woe') ->join('char', 'woe.char_id', '=', 'char.char_id') ->select('woe.kills_permanente', 'woe.deaths_permanente',…
-
0
votes3
answers171
viewsA: Doubt - Update SQL Server 2012
Declare a support table, populate it and use it to check if the title already has one month included: DECLARE @meses TABLE(numero INT, nome VARCHAR(10)); DECLARE @data_base DATE, @mes VARCHAR(10),…
-
3
votes1
answer573
viewsA: Problem row with priority
You will need two lists FIFO that in Java can be obtained using LinkedList: FIFO In Computer Science, FIFO (acronym for First In, First Out, which in Portuguese means first to enter, first to exit)…
-
2
votes2
answers61
viewsA: Procedure sql server 2012 + java
It would look more or less like this: CallableStatement cs = conexao.prepareCall("{ ? = call dbo.MEJT_SP_CAD_PRODUT(?, ?, ?, ?, ?, ?, ?) }"); int id; cs.registerOutParameter(1, Types.INTEGER);…
-
1
votes1
answer214
viewsA: Linked SQL Server and Firebird: Error 'Must declare the scalar variable'
If you want to return the value in a variable, replace the EXECUTE for sp_executesql: EXECUTE sp_executesql @OPENQRY, N'@QtdReg VARCHAR(7000) OUTPUT', @QtdReg = @QtdReg OUTPUT; sp_executesql Runs a…
-
2
votes2
answers356
viewsA: Take any variable from an array that has a certain id in Angularjs
Unfiltered: var filtrado = $scope.listademercadoria(function(item) { return item.id === 2; })[0]; With $filter: var filtrado = $filter('filter')($scope.listademercadoria, {id: 2})[0]; Then you use…
-
1
votes1
answer159
viewsA: Sort by id in Angularjs (Javascript)
You can use the $filter orderBy: $scope.listaDoCarrinho = $filter('orderBy')($scope.listaDoCarrinho, 'id'); But look, your attribute id is a String, therefore it will be ordered alphabetically.…
-
1
votes1
answer156
viewsA: Compare group by sql server values
Group the results by counting them. After that take the minimum with the fewest repetitions. WITH repeticoes AS ( SELECT sp.empresa, sp.idloteproduto, sp.serie, sp.saiu, sp.id, COUNT(sp.id) AS…
-
5
votes3
answers775
viewsA: How can I make a copy of multiple tables in a new table using SQL SERVER?
You can insert using the template below: INSERT INTO tabelan(coluna1, coluna2, coluna3, coluna4, colunaz) SELECT coluna1, coluna2, coluna3, coluna4, colunaz FROM tabela1 UNION SELECT coluna1,…
-
1
votes2
answers917
viewsA: How to reduce the running time of a query in SQL server?
Try to replace the CURSOR for INSERT as follows: DECLARE @resultado TABLE( banco VARCHAR(MAX), tabela VARCHAR(MAX), rodovia VARCHAR(MAX), elemento VARCHAR(MAX), n_foto INT, data_sincronizacao…
-
0
votes2
answers569
viewsA: Split a query
If the intention is to separate the first 3 CASE, you can do it this way: -- Sem deslocamento SELECT 'Sem deslocamento' AS Title, COUNT(1) AS Count FROM jud_processos jp WHERE jp.status = 1 AND…
-
2
votes2
answers444
viewsA: Join returning many records
The problem is that the JOIN is the result of joining the rows of table A with table B. The clause ON restricts the results of this junction. Then you should build the ON of JOIN based on the…
-
0
votes1
answer691
viewsA: How to verify, amid a select, the existence of relationship of a record of an A table with records of other tables
What you want can be accomplished with the clause EXISTS, which means EXISTENCE: SELECT prod.* FROM produtos prod WHERE EXISTS(SELECT 1 FROM promocional promo WHERE promo.prod_id = prod.prod_id)…
-
1
votes3
answers259
viewsA: Filter a select, without duplicate SQL queries being returned
To reach the desired result you must use the clause EXISTS together with NOT: SELECT a.* FROM agendamentos a WHERE NOT EXISTS(SELECT 1 FROM agendamento_aceitos aa WHERE aa.schedule_id =…
-
14
votes12
answers79762
viewsA: Formatting Brazilian currency in Javascript
You can use regular expressions for this: function formatarMoeda() { var elemento = document.getElementById('valor'); var valor = elemento.value; valor = valor + ''; valor =…
javascriptanswered Sorack 27,430 -
1
votes2
answers231
viewsA: Difficulty reading XML in Java
You have to add class annotations Car: import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "Car") public class Car { private String…
-
7
votes2
answers10963
viewsA: What is the difference between SET and ENUM in Mysql?
TL;DR SET lets you save a collection. ENUM allows only unit values. Documentation According to Mysql documentation ENUM and SET Constraints: ENUM and SET Columns provide an Efficient way to define…
-
1
votes1
answer235
viewsA: Update with select CTE Error
Do not update the field on CTE and yes in your table tarefa as follows: WITH historico AS ( SELECT t.taridinclusao AS tarefa_inclusao, t.tarid AS tarefa_referencia, 1 AS nivel FROM tarefa t WHERE…
-
0
votes1
answer50
viewsA: Controller by file in angular js
First check if you imported the script of your controller in a tag <script in the html. Change the statement of your controller to find the module registered in AngularJS by name. After that…
-
4
votes1
answer143
viewsA: Sign + before function in Jquery? what does it mean?
The + in front of the function serves to execute it immediately IIFE (Immediately Invoked Function Expression). If there is no such operator or any other way of indicating that the function will be…
-
3
votes1
answer542
viewsA: Invalid Colum name
The flaps of SQL Server Management Studio work with local cache, so, according to the documentation, use the shortcut keys CTRL+SHIFT+R to update. Shortcut documentation in English can be found at…
sql-serveranswered Sorack 27,430 -
1
votes1
answer92
viewsA: Problems with hashmap getordefault in java
You’re saving the list carros for all tags. Instead create one for each: for (Car c : carros){ List<Car> lista; if (mapCarros.containsKey(c.getManufacturerCar())) { lista =…
-
3
votes1
answer79
viewsA: Is it possible to change a user-defined table type?
There is no possibility to change the type directly. What you can do is use the sp_rename to rename the type with a temporary name, re-create it with the new settings and update the dependencies…
-
1
votes2
answers4640
viewsA: LEFT JOIN WITH GROUP BY
In this case as you just want the amount of likes you can use a subquery to get the count: SELECT p.*, (SELECT COUNT(1) FROM curtida c WHERE c.id_postagem = p.id) AS curtidas FROM postagem p See…
-
1
votes1
answer1258
viewsA: compare and add in sequence with sql server
FORM 1: The following query: -- Gera uma coluna "sequencia" para ser utilizada de referência WITH referencia AS ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) AS sequencia, t.* FROM tabela t ), --…
-
2
votes2
answers454
viewsA: How to sum up all the elements of an ng-repeat?
You can create a function that returns the sum executed in controller. Note that I did this in the example below with the function somar: angular .module('meumodulo',[])…
-
1
votes2
answers904
viewsA: How to reference the variable within HTML through Angularjs?
The problem is that you are using the $rootScope in the html. The ideal is not to use $rootScope and yes the this to share data with view. You’re also using the push in the array, therefore you…
-
3
votes3
answers932
viewsA: Current or formal argument lists differs in length
The error says: Current or formal argument lists differs in length That is to say The lists of real or formal arguments differ in length Your method verifyWord receives two parameters, a String and…
-
1
votes1
answer879
viewsA: How to search data from a table using other reference?
Use the clause EXISTS together with NOT: SELECT p.* FROM produtos p WHERE NOT EXISTS(SELECT 1 FROM comprasdosusuarios cdu WHERE cdu.id_produtos = p.id AND cdu.id_user = 1) AND p.nomedoproduto LIKE…
-
1
votes1
answer68
viewsA: SQL Server Doubt 2012 - Query
Use a recursive search to find the primordial record for the desired task: WITH historico AS ( SELECT t.taridinclusao AS tarefa_inclusao, t.tarid AS tarefa, 1 AS nivel FROM tarefa t WHERE t.tarid =…