aggregate-functions

Datatable Compute Method Convert string column to date

一笑奈何 提交于 2019-12-25 02:34:29
问题 I have a column in datatable having dates with format dd/MM/yyyy HH:mm . I fill the datatable using the code below which is common for more than 1 select statements so i cannot specify column and their datatype before filling the datatable. Any manipulation after filling the data is acceptable to me. data_adapt = New OracleDataAdapter(query, OraConn) dt = New DataTable data_adapt.Fill(dt) For paging i create a copy of the datatable using skip and take as below dtLineupCopy = New DataTable

MySQL Group By get title column with smallest date value

╄→гoц情女王★ 提交于 2019-12-25 02:13:38
问题 I have a query like: SELECT * FROM table GROUP BY sid ORDER BY datestart desc LIMIT 10 which returns the last 10 sid groups. For each of these groups, I need the title column of the row with the lowest datestart value I tried using SELECT *, min(datestart) but that didn't return the row with the smallest datestart value, just the lowest datestart. I need the title from the lowest datestart. (Relevant) Table Structure: CREATE TABLE `table` ( `title` varchar(1000) NOT NULL, `datestart`

SQL group function nested too deeply

房东的猫 提交于 2019-12-25 01:55:46
问题 I want to make a SQL query which finds the pname of parts which are the least repeated in supplier_parts_shipment . Table 1 supplier (sno, sname, city) 1, ahmad, jeddah 2,kaled,med 3,njwa,med Table 2 parts (pno, pname, color) 1, laptop, red 2,keybord,blue Table 3 supplier_parts_shipment (shno, sno, pno, date) 1,1,1,2014 2,2,1,2014 3,3,2,2014 I tried something like this: SELECT pname , min(count(pno)) FROM parts WHERE pno IN (SELECT pno FROM supplier_parts_shipment group by pname HAVING min

Group by quarter (datepart) returns multiple rows with same quarter

不羁岁月 提交于 2019-12-25 00:09:25
问题 I'm trying to return a count for the total number of records in the table HISTORY grouped by their quarter and year. Currently I have: SELECT DISTINCT (CAST(DATEPART(year, CREATE_DATE) AS char) + ' Qtr' + CAST(DATEPART(quarter, CREATE_DATE) AS char)) AS Period, COUNT(ID) FROM HISTORY GROUP BY CREATE_DATE ORDER BY Period; But I'm getting duplicate rows with the same quarter and year. I'm also getting a total of records counted that's lower than the total records in the table. Here's a sample

How do I sum only the 3 best scores from this query?

坚强是说给别人听的谎言 提交于 2019-12-24 20:43:57
问题 I need to sum only the 5 best scores for each player from 11 events. The query below creates a leaderboard which sums all the scores but I'm stuck as to how i can only sum the 5 best scores. I've abbreviated the query to show only 4 events and getting best 3 results to shorten the post, but hope it gets across, what I need. SELECT playerID AS Player, SUM(CASE WHEN championshipleaderboard.eventID = 1 THEN championshipleaderboard.points ELSE 0 END) AS Event1, SUM(CASE WHEN

Why do I get “ORA-00932: inconsistent datatypes: expected - got -” when using COLLECT() in a prepared statement?

百般思念 提交于 2019-12-24 16:57:18
问题 I am using this query with the Perl DBI: SELECT c.change_id , COLLECT(t.tag) AS the_tags FROM changes c LEFT JOIN tags t ON c.change_id = t.change_id WHERE c.project = ? GROUP BY c.change_id The DBI uses OCI to prepare this statement, bind the value I pass, and get the results. But Oracle, for some reason, does not like it. The error output is: ORA-00932: inconsistent datatypes: expected - got - (DBD ERROR: error possibly near <*> indicator at char 41 in ' SELECT c.change_id , <*>COLLECT(t

Groupwise maximum query for getting records for latest date

萝らか妹 提交于 2019-12-24 16:52:09
问题 I'm trying to build a query that only gets the latest record on a group of records based on date. The layout of the table is following: | date | category | action | label | label2 | count_today | count_total | period | The primary key is based on the columns date , category , action , label , label2 , period . date has format yyyy-mm-dd and period can have the values Day , Week , month . For each unique combination of category | action | label | label2 I need to have the record with the

Concat rows in Postgres

一个人想着一个人 提交于 2019-12-24 16:48:51
问题 Given is a Postgres table like this nummer vorname name cash ------|-----------|-----------|----- 1 paul smith 500 2 andy london 700 2 mike dover 700 3 clara winchester 200 To query this table my sql looks like this right know: SELECT nummer, vorname, name, cash as total FROM data.myTable GROUP BY nummer, name, vorname, cash ORDER BY nummer; Is it possible to concat the two rows where nummer is the same (in this case 2 ). Means my output should look like this (cash will also have the same

Concat rows in Postgres

泪湿孤枕 提交于 2019-12-24 16:48:04
问题 Given is a Postgres table like this nummer vorname name cash ------|-----------|-----------|----- 1 paul smith 500 2 andy london 700 2 mike dover 700 3 clara winchester 200 To query this table my sql looks like this right know: SELECT nummer, vorname, name, cash as total FROM data.myTable GROUP BY nummer, name, vorname, cash ORDER BY nummer; Is it possible to concat the two rows where nummer is the same (in this case 2 ). Means my output should look like this (cash will also have the same

Function equivalent to SUM() for multiplication in SQL Reporting

二次信任 提交于 2019-12-24 14:16:33
问题 I'm looking for a function or solution to the following: For the chart in SQL Reporting i need to multiply values from a Column A. For summation i would use =SUM(COLUMN_A) for the chart. But what can i use for multiplication - i was not able to find a solution so far? Currently i am calculating the value of the stacked column as following: =ROUND(SUM(Fields!Value_Is.Value)/SUM(Fields!StartValue.Value),3) Instead of SUM i need something to multiply the values. Something like that: =ROUND