group-by

SQL: query to show how many users have each property (grouped)

给你一囗甜甜゛ 提交于 2019-12-25 08:37:35
问题 I'm new to SQL and can't seem to ask the right question, as in every time I formulate it differently I end up with the same results: A query that groups data by several properties (users that share more than one property). I'm writing a JSP-based website on the Glassfish server, and manage the database from MS Access. What I'm interested in, is basically grouping by several distinct properties. Say I have a table that shows which items a user has. Something like this: id | name | item1 |

SQL: Get latest entries from history table

走远了吗. 提交于 2019-12-25 08:26:39
问题 I have 3 tables person (id, name) area (id, number) history (id, person_id, area_id, type, datetime) In this tables I store the info which person had which area at a specific time. It is like a salesman travels in an area for a while and then he gets another area. He can also have multiple areas at a time. history type = 'I' for CheckIn or 'O' for Checkout. Example: id person_id area_id type datetime 1 2 5 'O' '2011-12-01' 2 2 5 'I' '2011-12-31' A person started traveling in area 5 at 2011-12

group by and order by in mysql query

廉价感情. 提交于 2019-12-25 07:49:22
问题 I am working on dating website with php and mysql as backend. I've two tables. First table is user table where all user info will be stored and other table is visituser table where if one user view another users profile then there will be an entry in visituser table. Every time if one user visits another users profile then there will be an entry in visituser table. There will be multiple entry for one user visit to another user. My problem is that i've to show the visitor one time with latest

GroupBy LINQ statement

不羁岁月 提交于 2019-12-25 07:24:50
问题 I have a list of Questions that is grouped by Subject and Parent. For example I would have Subject 1 Parent 1 Question 1 Subject2 Parent2 Question2 Subject1 Parent2 Question3 Subject2 Parent2 Question4 Now I wish to display some sort of tree view, ie something like Subject 1 Parent 1 Question 1 Parent 2 Question 2 Question 3 Subject 2 Parent 1 Question 4 Parent 2 Question 5 Question 6 How can I achieve that with GroupBy LINQ statement? I have tried something which is not working yet var

SQL Query to get empty categories too

那年仲夏 提交于 2019-12-25 07:24:11
问题 In my categories table I have: cat_id , cat_name , cat_slug . In the table items I have: item_title, item_id , item_category . `item_category` = `cat_id` I'm using the following SQL to get "all" categories and how many items they have: SELECT *, COUNT(`item_id`) FROM `menu_categories` JOIN `menu_items` ON `item_category` = `cat_id` GROUP BY `item_category` But it doesn't show empty categories , i.e. categories without items. 回答1: You need to use LEFT JOIN instead of JOIN SELECT *, COUNT(`item

Complex MySQL JOIN with GROUP BY

六眼飞鱼酱① 提交于 2019-12-25 07:16:17
问题 I want to return a report that looks like the following: unit | days | stays | income | charges | mgmt fee | bal 1001 20 6 775.00 1500.00 310.00 0.00 1002 40 14 5000.00 200.00 2100.00 2700.00 1003 50 20 6000.00 10.00 2500.00 3490.00 So the bal is (income - (charges+mgmt fee). I have tables that look like this: Unit id | name | mgmt_fee 1001 blossom 30 1002 charlie 25 1003 deniro 30 1004 archie 20 1005 lilly 25 The mgmt fee is used as a percentage (%) Reservations id | unit | arrival | depart

MySQL Query with Group By

人走茶凉 提交于 2019-12-25 06:28:28
问题 I have played around with many different queries, but haven't been able to locate the right syntax for this project.. I really hope someone can make sense of my mess. I have a table with orders, one row per order, and each row containing info such as the customer number, PO#, and date of the order. A PO number can be tied to one or more orders, which is where I am getting lost. I am trying to create a query that will produce a single row containing the customer number, PO#, date of the

Create a query to select two columns; (Company, No. of Films) from the database

﹥>﹥吖頭↗ 提交于 2019-12-25 06:12:29
问题 I have created a database as part of university assignment and I have hit a snag with the question in the title. More likely I am being asked to find out how many films each company has made. Which suggests to me a group by query. But I have no idea where to begin. It is only a two mark question but the syntax is not clicking in my head. My schema is: CREATE TABLE Movie (movieID CHAR(3) , title CHAR(36), year NUMBER, company CHAR(50), totalNoms NUMBER, awardsWon NUMBER, DVDPrice NUMBER(5,2),

Group by a variable range in mysql / MariaDB

纵饮孤独 提交于 2019-12-25 06:09:08
问题 I have a history log and i want to summarize some entries. The interval should be 5 seconds For example: I have a list date_start | date_end | count | somestring 2015-09-15 12:04:09 | 2015-09-15 12:04:09| 1 | xyz 2015-09-15 12:05:09 | 2015-09-15 12:05:09| 1 | xyz 2015-09-15 12:05:10 | 2015-09-15 12:05:10| 1 | xyz 2015-09-15 12:05:11 | 2015-09-15 12:05:11| 1 | xyz 2015-09-15 12:06:09 | 2015-09-15 12:06:09| 1 | xyz I want now to have an output like date_start | date_end | count | somestring

How to do group by substring in Eclipselink?

醉酒当歌 提交于 2019-12-25 05:51:17
问题 I'm trying to group the store by store country and see how many stores there are in each country. The store country happens to be the first 2 characters of the store's code. That means if the store code is "US000010", the country is "US" My entity object: ... public class Store { @column(name = "code") private String code; ... } My JPQL is: SELECT substring(s.code, 0, 2), count(s) FROM Store s GROUP BY substring(s.code, 0, 2) This keeps throwing me ORA-00979: not a GROUP BY expression , which