source: database/Advanced Reports for database/Approximate number of orders per client@ 62b2964

finki-main main
Last change on this file since 62b2964 was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 533 bytes
Line 
1CREATE OR REPLACE FUNCTION get_approximate_orders_per_client()
2RETURNS TABLE (
3 total_clients BIGINT,
4 total_orders BIGINT,
5 approximate_orders_per_client NUMERIC
6)
7LANGUAGE plpgsql
8AS $$
9BEGIN
10 RETURN QUERY
11 SELECT
12 (SELECT COUNT(*) FROM client) AS total_clients,
13 (SELECT COUNT(*) FROM "order") AS total_orders,
14 ROUND(
15 (SELECT COUNT(*) FROM "order")::NUMERIC
16 / NULLIF((SELECT COUNT(*) FROM client), 0),
17 2
18 ) AS approximate_orders_per_client;
19END;
20$$;
Note: See TracBrowser for help on using the repository browser.