spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

SELECT DISTINCT TWO COLUMNS and SUM another COLUMN's VALUES


Please Try this.

SELECT
e.id,
SUM(price) AS 'price',
g. NAME
FROM
    tbl_expense e
INNER JOIN tbl_gasoline g ON e.GasolineType = g.id
GROUP BY
    g.id,g. NAME

Categories : SQL

Related to : SELECT DISTINCT TWO COLUMNS and SUM another COLUMN's VALUES
Sprade distinct values over a different columns
It can be done with dynamic sql declare @query varchar(max); declare @values varchar(max) = null; with distinctValues as ( select distinct cast(value as varchar(20)) as value from myTable ) select @values = COALESCE(@values + ', ['+ value + ']', '['+ value + ']') from distinctValues; set @query = 'select [id], ' + @values + 'from myTable pivot ( count(value) for value in (' + @values + '))

Categories : SQL
Set certain values in column B by matching it to another pair of columns
In the first sheet, use a VLOOKUP function to find corresponding matches in the second sheet (I'll call that Sheet2. with IFERROR to catch no matches. In the first sheet's B2 cell, use this formula, =IFERROR(VLOOKUP($A2, 'Sheet2'!$A:$B, 2, FALSE), "") VLOOKUP function That will return the first value in column B that corresponds to a matching value in column A which seems to be what you want.

Categories : Excel
Select sets of values from R matrix column
Try H[cbind(seq_len(nrow(H)), P)] ## [1] 0.6733731 0.7396847 0.5953580 Here we are indexing by consecutive rows and columns indicated in P Regarding your question, so the reason H[, P] returns a matrix is because you are telling R: select all rows in columns: 2, 1, 2 from matrix "H" thus the result that you are getting is a matrix with identical first and third columns.

Categories : R
Extending the result set adding columns taken from another table's distinct rows
Something like SELECT u.id, u.name, (SELECT COUNT(c.uid) FROM CHOICE WHERE c.kname = 'city1') AS city1, (SELECT COUNT(c.uid) FROM CHOICE WHERE c.kname = 'city2') AS city2, (SELECT COUNT(c.uid) FROM CHOICE WHERE c.kname = 'city3') AS city4, (SELECT COUNT(c.uid) FROM CHOICE WHERE c.kname = 'city4') AS city4 FROM USER u INNER JOIN CHOICE c ON u.id = c.uid GROUP BY u.id, u.name

Categories : Mysql
Compare Column A to Column B and copy items that are in both columns into Column C
You can use =IF(RIGHT(A1,LEN(A1)-FIND(".",A1))=RIGHT(B1,LEN(B1)-FIND(".",B1)),RIGHT(A1,LEN(A1)-FIND(".",A1)),"No") =RIGHT(A1,LEN(A1)-FIND(".",A1)) will return website.com from a cell even if it starts with http:// or http://www. or www. The above formula just compares the website from each column and if it is a match, it will return the website, otherwise return "No"

Categories : Excel
Recently Add
SQL command to insert two primary keys into third table
How to do a registerform by ASP.NET VB SQL
Shortest time and trip between two stops across many trip options (GTFS)
Using IN and EXISTS subquery with AND operation instead of OR?
How to select multiple alias columns from the same table
Delete records from a given table
date manipulation in postgresql
PSQL query with join query from a db newbie
Protect LocalDB from user access
Update field with combined contents from other fields
SQL select unique records under certain priority and conditions from multiple columns
Multiply quantities for all parent child relationships
I'm having an issue running a query from a batch file
Concatenate strings while filtering by another column in SQL Server view
Parsing Dynamic XML to SQL Server tables with Parent and child relation
Using MERGE for delete and insert in oracle
how to display the pre value and post value of a column after updating it?
sql loop to fill up date between two time stamps
With SQL/TSQL, how can I use STUFF within this WHILE clause?
Challenging db table and query
Query to fetch row corresponding to Max value in SQL
Oracle SQL - ORA-00936 on DATE()
how to split single row into multiple row in db2?
Combine fields into one column
How can I perform an SQl where query then list properly?
SQL - Selection of the oldest order for every customer (join two tables)
Sum two counts in a new column without repeating the code
Creating multiple sum fields based upon criteria in another field in MS access 2007
Grouping by two values in same table
MS SQL last record
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.