Questions tagged as 'sql'

2
answers

How to display total records in a ManyToMany relationship when I use HAVING?

I have the tables below: articles tags article_tag (pivot table with article_id and tag_id columns) In the query below I can retrieve articles that have both tags (with id 1 and 3). In the query only articles that have the two tags th...
asked by 07.01.2016 / 04:04
1
answer

Run 2 queries at the same time is it possible?

I need to change all the fields in a table and insert only one row in another row. I am using the following code $Nid = intval($_GET['Nid']); $sql = "UPDATE * FROM programacao SET status='offline' WHERE status ='online' "; $sql2 = "UPDATE pr...
asked by 20.02.2016 / 00:55
1
answer

Doubt with Date formatting in sql server 2008

In my application I'm writing the dates in this format: DateTime.Now.ToString("yyyy/MM/dd"); In the database I have: 2016-01-09 00:00:00.000 Now I need to make an appointment where I will bring only the records of the day. selec...
asked by 11.01.2016 / 01:09
1
answer

Get Total value with the exception of date

I am trying to develop a query that returns me a total value of requests from a given client, with an informed date range. For example, between 05/11/2015 and 05/12/2015. The problem is that I need to make the exception for a few days between...
asked by 09.12.2015 / 14:34
1
answer

Case and Group by Error - Oracle SQL Developer

Hello, I'm trying to group the results of a query with case as follows: select case when sal BETWEEN 0 and 100000 then 1 when sal BETWEEN 100001 and 200000 then 2 when sal BETWEEN 200001 and 300000 then 3 when sal...
asked by 07.12.2015 / 18:25
1
answer

Select Comparing Periods

I need to make a select that compares two sales periods, totaling by product. Today I have this select that does this, but only for a period (01/09/2014 to 09/30/2014) SELECT ACC.PRODUTODESC PRODUTO, Sum(ACC.VALORTARIFA)...
asked by 05.02.2016 / 15:03
1
answer

Choose second lowest occurrence in a trigger

Trigger that prevents a candidate who has stayed in the penultimate place during the last two months you can apply for a new job So what I need to do is to insert the data into the table ficha_inscricao check if this candidate was not...
asked by 27.11.2015 / 16:40
1
answer

Intermediate table of relationship n for n [closed]

I have two tables with N to N in my database, so I should create an intermediate table that has the PK of each of those two tables. My question is: how to enter data by correctly referencing the PKs in the middle table?     
asked by 26.10.2015 / 17:50
1
answer

SQL - How to count days worked

The ACESSOBROA_NOVO table registers the access of company employees whenever they go through a ratchet. I need to do a query in this table that lists the names of the employees and counts the days worked in a period of, for example, 5 days....
asked by 21.10.2015 / 21:57
2
answers

Difficulty to Mount SQL Query with UNION with SUM

I have 2 tables that stores different sales type, and I need to add everything to get the value to generate the collection, but I'm not able to mount the sql query, as follows: SELECT CL.NOME,CL.id_cadastro_cliente, sum (L.VALOR_LANCAMENTO) a...
asked by 14.12.2015 / 20:19