SQL: return many to many in one table

Using a MySQL database I want to store daily measurements of different "channels": date | channel | value -----+---------+------ 1.1. | 'A' | 1 1.1. | 'B' | 2 1.1. | 'C' | 3 2.1. | 'A' | 4 2.1. | 'C' | 5 3.1. ...
more »

2017-09-18 22:09 (1) Answers

Why I can't obtain record in a range of date?

I am not so into SQL and I have to create a complex query. My idea is start to a simple query and enrich it step by step. I am using MySql I ahve some doubts about a possible smart way for the first step. So I have a MeteoForecast table like this: ...
more »

2017-09-18 17:09 (1) Answers

T-SQL: Filtering columns by date

I am trying to generate columns based on the date of the activity. I used FULL JOIN before but it only generated duplicated rows even when using CASE. Some guidance on how to approach this would be great. Table 1 is my current data and Result is the...
more »

2017-09-17 17:09 (2) Answers

Can I use OR when joining two tables?

SELECT Notifications.message, BusinessAccounts.employee_username FROM Notifications, BusinessAccounts WHERE Notifications.notification_by_business_account_id = BusinessAccounts.account_id AND Notifications.notification_business_id=5 In this situati...
more »

2017-09-17 03:09 (1) Answers

Sql get sum row by row

I have one table it looks like below ID | PName | Price ___+_______+______ 1 |some |2000 2 |some |3000 3 |some |250 now i need to query for get following result ID | PName | Price |Total Price ___+_______+________+____________ 1 |some ...
more »

2017-09-16 16:09 (1) Answers

Big database project on ASP.NET MVC

I'm working on really nice project in ASP.NET MVC, where comapnies can generate some pdf documents, save some data etc. I have a piece of project already. [no important] Programist will add Company with one AdminUser, AdminUser[Boss of company or sm...
more »

2017-09-16 14:09 (1) Answers

If Exists command in setting a variable

I've got a working IF EXISTS command to select a PID_GUID that's already in the tables, or to select a value to use as a PID_GUID if it does not exist already in the tables. The command looks like this; IF EXISTS (SELECT PID_GUID FROM PID WHERE EDI_...
more »

2017-09-15 20:09 (2) Answers

data set to json with group

I am working on an angular + nodejs application and I need some data from sql in json format. I am able to get the data in json but I need the data to be grouped in a tree like manner. Is there a way to do this in sql, server or in front end level? ...
more »

2017-09-15 14:09 (2) Answers

Multiplication of Case Column in SQL

I have a query where i have two column based on Case, i wish to multiply Qty_Sold * UnitPrice to get Result SELECT CASE WHEN RPT_ITM_D.F1034 = 3 THEN F64 ELSE 0 END AS Qty_Sold ,CASE WHEN [POS_TAB].F...
more »

2017-09-15 09:09 (2) Answers

Set multiple order by in mysql query

I have a table of users which contain some information of users. id | name | country ------------------------------ 1 | user1 | India 2 | user2 | China 3 | user3 | United State 4 | user4 | India 5 | user5 | Shri Lanka ...
more »

2017-09-14 11:09 (2) Answers

Inserting data into multiple tables at same time

This is what I am trying to do: Let's say I have two tables dbo.source & dbo.destination I want to copy all records from source to destination IF a certain natural key (unique non clustered) does not exist in the destination. If the insert is su...
more »

2017-09-13 21:09 (2) Answers

Display most recent date for out status

I'm pulling my hair out trying to figure this out. I have a query that will display IN and Out Status and Datetime in two separate columns(originally in same column). The query will return the results the way I need them but the OUT dates are displ...
more »

2017-09-13 20:09 (2) Answers

SQL Server get latest value by date

I have a SQL Server table that has project_id int,update_date datetime ,update_text varchar(max) The table has many updates per project_id. I need to fetch the latest by update_date for all project_id values. Example: project_id update_date ...
more »

2017-09-13 19:09 (4) Answers