Questions tagged as 'query'

2
answers

How to change a query so that it is executed for each row of the X table?

I have the following database query working: SET @orderid := '1'; INSERT INTO 'cart_lines' ( 'line_id' , 'cart_id' , 'book_id' , 'book_reference' , 'book_name' , 'book_type' , 'unit_price' , 'quantity' , 'date_created' , 'date_updated' ) SEL...
asked by 26.12.2013 / 17:55
1
answer

Select random ID between 2 and 4

Is it possible to randomly select the ID, for example by entering ID numbers that can be drawn (2/4)? Note: Only one line of this selection should be returned. I put this code but it was not: SELECT descricao FROM TABLE ORDER BY RAND I...
asked by 18.10.2018 / 06:34
3
answers

count the same database text in php

Good morning, my question is this: in my case I have a table in the database that allows to evaluate a service, the classification is made by colors "red, yellow and green", ie the type is text . What I wanted to do is query in...
asked by 07.06.2018 / 10:22
1
answer

Count / Dense_rank grouped sql

I'm trying to group the rows by group in sqlserver and as a result I want to: CICLO | CODFIL | CODITPROD | ROW 1 | 1 | 10 | 1 11 | 1 | 10 | 2 12 | 1 | 10 | 3 1 | 2 | 10 | 1 11...
asked by 23.05.2018 / 16:17
2
answers

Divide a query

I need your help, I have a query in my system, which has 4 cases SELECT TOP 3 * FROM ( SELECT Title, SUM(Count) AS Count FROM ( SELECT CASE WHEN EstadoId = EstadoIdAutor AND EstadoId = Meddoc1 AND Estado...
asked by 03.10.2017 / 14:07
1
answer

Foreach with 2 conditions

I'm trying to put two conditions in the foreach, but I'm not having success. The idea is as follows: the client accesses the website at the following URL: / room / balcony and only products that have in their database in the DB the room environm...
asked by 29.10.2017 / 00:54
2
answers

How to make a query that just counts an unbroken stream?

I want to count uninterrupted values of the current year back until the first NULL occurs. Example:    Several people make donations to an NGO annually and this is   stored in a database, I would like to know how many years a   pers...
asked by 30.11.2017 / 13:34
1
answer

Error Code: 1054. Unkowm column

I want to query a value from an account I made in SQL: (Valor - (select Visibilidade)) AS Diferenca When I try to query: Diferenca <= 500 It displays the following error: Error Code: 1054. Unknown 'Diferenca' in 'w...
asked by 19.09.2017 / 20:37
2
answers

Dateadd Hours - SQL Server

Everyone, I have a question. In the query below, in the field titling, he counts the hours normally, however, I want you to count only the working hours. NOTE: You already have a working hours function called working_hours NOTE: This variable...
asked by 06.11.2017 / 21:19
1
answer

Search in multiple tables

Hello, I'm trying to search in 3 different tables, see my code: $buscando = $pdo->query("SELECT * FROM filmes WHERE nome LIKE '%$busca%' AND status='ativo' ORDER BY nome ASC"); The tables would be: animes, films and series. All have the...
asked by 19.08.2017 / 00:25